--- mess
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <QComboBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QProgressBar>
|
||||
#include <QSlider>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QHeaderView>
|
||||
@@ -39,7 +40,8 @@ public:
|
||||
registerEditor(XQItem::LineEditType, new QStandardItemEditorCreator<QLineEdit>());
|
||||
registerEditor(XQItem::ComboBoxType, new QStandardItemEditorCreator<QComboBox>());
|
||||
registerEditor(XQItem::PickerType, new QStandardItemEditorCreator<QLineEdit>());
|
||||
registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QProgressBar>());
|
||||
//registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QProgressBar>());
|
||||
registerEditor(XQItem::ProgressBarType, new QStandardItemEditorCreator<QSlider>());
|
||||
registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator<QSpinBox>());
|
||||
registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator<QLineEdit>());
|
||||
}
|
||||
@@ -91,11 +93,15 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
|
||||
case XQItem::ComboBoxStyle :
|
||||
return drawComboBoxStyle( painter, option, index );
|
||||
|
||||
case XQItem::SpinBoxStyle :
|
||||
return drawSpinBoxStyle( painter, option, index );
|
||||
|
||||
case XQItem::ProgressBarStyle :
|
||||
return drawProgressBarStyle( painter, option, index );
|
||||
|
||||
case XQItem::HiddenStyle :
|
||||
return;
|
||||
|
||||
//case XQItem::ProgressBarStyle :
|
||||
// return drawProgressBarStyle( painter, option, index );
|
||||
|
||||
|
||||
default:
|
||||
@@ -113,8 +119,7 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
|
||||
{
|
||||
QStyleOptionHeader headerOption;
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
// use the header as "parent" for style init
|
||||
QWidget* srcWidget = treeTable();//->header();
|
||||
headerOption.initFrom(srcWidget);
|
||||
@@ -147,40 +152,44 @@ void XQItemDelegate::drawHeaderStyle(QPainter* painter, const QStyleOptionViewIt
|
||||
|
||||
void XQItemDelegate::drawProgressBarStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QStyleOptionProgressBar progressBarOption;
|
||||
progressBarOption.rect = option.rect;
|
||||
progressBarOption.state = option.state;
|
||||
progressBarOption.direction = option.direction;
|
||||
progressBarOption.fontMetrics = option.fontMetrics;
|
||||
progressBarOption.palette = option.palette;
|
||||
progressBarOption.styleObject = option.styleObject;
|
||||
progressBarOption.minimum = 0;
|
||||
progressBarOption.maximum = 100;
|
||||
progressBarOption.progress = 67; // Fester Wert
|
||||
progressBarOption.text = QStringLiteral("67%");
|
||||
progressBarOption.textVisible = true;
|
||||
progressBarOption.textAlignment = Qt::AlignCenter;
|
||||
|
||||
int progress = index.data(XQItem::ContentRole ).toInt();
|
||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
|
||||
|
||||
QStyleOptionProgressBar progressBarOption;
|
||||
progressBarOption.rect = option.rect;
|
||||
progressBarOption.minimum = 0;
|
||||
progressBarOption.maximum = 100;
|
||||
progressBarOption.progress = progress;
|
||||
progressBarOption.text = QString::number(progress) + "%";
|
||||
progressBarOption.textAlignment = Qt::AlignCenter;
|
||||
progressBarOption.textVisible = true;
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar,&progressBarOption, painter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! firz
|
||||
//! Zeichnet das Item als combo box.
|
||||
|
||||
void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
|
||||
QWidget* srcWidget = qobject_cast<QWidget*>(option.styleObject);
|
||||
QStyleOptionComboBox comboOption;
|
||||
QStyle* comboStyle = srcWidget->style();
|
||||
|
||||
comboOption.initFrom(srcWidget);
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
// set options
|
||||
comboOption.rect = option.rect;
|
||||
comboOption.state = option.state | QStyle::State_Selected | QStyle::State_Enabled;
|
||||
// not editable => only visual, but painter needs to know it
|
||||
comboOption.editable = false;
|
||||
comboOption.currentText = index.data(Qt::DisplayRole).toString();
|
||||
comboOption.currentText = item.text();//index.data(Qt::DisplayRole).toString();
|
||||
// decoration (if any)
|
||||
comboOption.currentIcon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
|
||||
comboOption.iconSize = comboOption.currentIcon.actualSize(QSize(option.rect.height() - 3, option.rect.height() - 3));
|
||||
@@ -195,26 +204,52 @@ void XQItemDelegate::drawComboBoxStyle(QPainter* painter, const QStyleOptionView
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
//! firz
|
||||
|
||||
//! Zeichnet das Item als spin box.
|
||||
|
||||
void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
qDebug() << " --- jawas? SPINBOX!";
|
||||
bool isInt = false;
|
||||
// Den Wert aus dem Modell holen.
|
||||
QString textToShow = index.data(Qt::DisplayRole).toString();
|
||||
textToShow.toInt(&isInt);
|
||||
|
||||
// xx_fix!
|
||||
//int value = index.data(XQItem::ContentRole ).toInt();
|
||||
QStyleOptionSpinBox spinBoxOption;
|
||||
spinBoxOption.rect = option.rect;
|
||||
/*
|
||||
spinBoxOption.text = QString::number(value);
|
||||
spinBoxOption.textAlignment = Qt::AlignCenter;
|
||||
spinBoxOption.textVisible = true;
|
||||
*/
|
||||
if (isInt) {
|
||||
// ----- Schritt 1: Den Rahmen und die Pfeile der SpinBox zeichnen -----
|
||||
QStyleOptionSpinBox spinBoxOption;
|
||||
spinBoxOption.rect = option.rect;
|
||||
spinBoxOption.state = option.state;
|
||||
spinBoxOption.buttonSymbols = QAbstractSpinBox::UpDownArrows;
|
||||
spinBoxOption.stepEnabled = QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled;
|
||||
spinBoxOption.frame = true;
|
||||
|
||||
QApplication::style()->drawComplexControl(QStyle::CC_SpinBox,&spinBoxOption, painter);
|
||||
// Zeichnet den "komplexen" Teil des Steuerelements (Rahmen, Hintergrund, Pfeile)
|
||||
QApplication::style()->drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr);
|
||||
|
||||
|
||||
// ----- Schritt 2: Den Text an der richtigen Position zeichnen -----
|
||||
|
||||
// Ermitteln, wo genau das Textfeld innerhalb des Widgets gezeichnet werden soll.
|
||||
QRect textRect = QApplication::style()->subControlRect(
|
||||
QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr
|
||||
);
|
||||
|
||||
// Einen kleinen Innenabstand für den Text hinzufügen für besseres Aussehen.
|
||||
textRect.adjust(2, 0, -2, 0);
|
||||
|
||||
// Den Text aus dem Modell in das ermittelte Rechteck zeichnen.
|
||||
// Die Flags sorgen für die korrekte Ausrichtung (rechtsbündig, vertikal zentriert).
|
||||
painter->drawText(textRect, Qt::AlignRight | Qt::AlignVCenter, textToShow);
|
||||
|
||||
} else {
|
||||
// Fallback für alle anderen Datentypen.
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! firz
|
||||
//! Überschreibt QStyledItemDelegate::sizeHint(option, index);
|
||||
|
||||
QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
|
Reference in New Issue
Block a user