This commit is contained in:
Christoph Holzheuer
2025-09-09 16:22:59 +02:00
parent 809ef10c0d
commit cbe8b92582
9 changed files with 107 additions and 44 deletions

View File

@@ -28,6 +28,51 @@
#include <xqitemtype.h>
#include <xqviewmodel.h>
/*
#include <QStyledItemDelegate>
#include <QPainter>
#include <QApplication>
class BarDelegate : public QStyledItemDelegate {
public:
BarDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override {
// Standard-Zellenhintergrund zeichnen
QStyledItemDelegate::paint(painter, option, index);
// Wert aus dem Modell holen
bool ok;
int value = index.data().toInt(&ok);
if (!ok || value < 0 || value > 100)
return;
// Balkenbereich berechnen
QRect rect = option.rect.adjusted(4, 4, -4, -4); // etwas Padding
int barWidth = static_cast<int>(rect.width() * (value / 100.0));
// Balken zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QRect barRect(rect.left(), rect.top(), barWidth, rect.height());
QColor barColor = QColor(100, 180, 255); // z.B. hellblau
painter->setBrush(barColor);
painter->setPen(Qt::NoPen);
painter->drawRect(barRect);
// Text (Zahl) zentriert zeichnen
painter->setPen(Qt::black);
painter->drawText(rect, Qt::AlignCenter, QString::number(value));
painter->restore();
}
};
*/
//! erzeugt eine editorfactory mit den hauseigenen editortypen.
@@ -40,8 +85,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<QSlider>());
//registerEditor(XQItem::ColorBarType, new QStandardItemEditorCreator<QProgressBar>());
registerEditor(XQItem::ColorBarType, new QStandardItemEditorCreator<QSlider>());
registerEditor(XQItem::SpinBoxType, new QStandardItemEditorCreator<QSpinBox>());
registerEditor(XQItem::CustomEditorType, new QStandardItemEditorCreator<QLineEdit>());
}
@@ -96,7 +141,7 @@ void XQItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
case XQItem::SpinBoxStyle :
return drawSpinBoxStyle( painter, option, index );
case XQItem::ProgressBarStyle :
case XQItem::ColorBarStyle :
return drawProgressBarStyle( painter, option, index );
*/
case XQItem::HiddenStyle :
@@ -289,6 +334,7 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
case XQItemType::ComboBoxType :
{
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
// wir erwarten hier ein gültiges model?
comboBox->setModel( item.fixedChoices());
comboBox->setCurrentText( item.data().toString() );
comboBox->showPopup();