diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 1a8194269c..63c527e807 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -49,6 +49,10 @@ PropertyEditor::PropertyEditor(QWidget *parent) setAlternatingRowColors(true); setRootIsDecorated(true); + + QStyleOptionViewItem opt = viewOptions(); + this->background = opt.palette.dark(); + this->groupColor = opt.palette.color(QPalette::BrightText); } PropertyEditor::~PropertyEditor() @@ -65,6 +69,26 @@ bool PropertyEditor::isAutomaticDocumentUpdate(bool) const return autoupdate; } +QBrush PropertyEditor::groupBackground() const +{ + return this->background; +} + +void PropertyEditor::setGroupBackground(const QBrush& c) +{ + this->background = c; +} + +QColor PropertyEditor::groupTextColor() const +{ + return this->groupColor; +} + +void PropertyEditor::setGroupTextColor(const QColor& c) +{ + this->groupColor = c; +} + QStyleOptionViewItem PropertyEditor::viewOptions() const { QStyleOptionViewItem option = QTreeView::viewOptions(); @@ -114,7 +138,7 @@ void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QM QStyleOptionViewItem opt = viewOptions(); PropertyItem *property = static_cast(index.internalPointer()); if (property && property->isSeparator()) { - painter->fillRect(rect, opt.palette.dark()); + painter->fillRect(rect, this->background); //} else if (selectionModel()->isSelected(index)) { // painter->fillRect(rect, opt.palette.brush(QPalette::Highlight)); } diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index b23d6db302..d65d7d17fc 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -41,10 +41,26 @@ namespace Gui { namespace PropertyEditor { class PropertyModel; +/*! + Put this into the .qss file after Gui--PropertyEditor--PropertyEditor + + Gui--PropertyEditor--PropertyEditor + { + qproperty-groupBackground: gray; + qproperty-groupTextColor: white; + } + + See also: https://man42.net/blog/2011/09/qt-4-7-modify-a-custom-q_property-with-a-qt-style-sheet/ + +*/ + class PropertyEditor : public QTreeView { Q_OBJECT + Q_PROPERTY(QBrush groupBackground READ groupBackground WRITE setGroupBackground DESIGNABLE true SCRIPTABLE true) + Q_PROPERTY(QColor groupTextColor READ groupTextColor WRITE setGroupTextColor DESIGNABLE true SCRIPTABLE true) + public: PropertyEditor(QWidget *parent = 0); ~PropertyEditor(); @@ -57,6 +73,11 @@ public: void setAutomaticDocumentUpdate(bool); bool isAutomaticDocumentUpdate(bool) const; + QBrush groupBackground() const; + void setGroupBackground(const QBrush& c); + QColor groupTextColor() const; + void setGroupTextColor(const QColor& c); + protected: virtual void closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint); virtual void commitData (QWidget * editor); @@ -72,6 +93,8 @@ private: bool autoupdate; bool committing; bool delaybuild; + QColor groupColor; + QBrush background; }; } //namespace PropertyEditor diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.cpp b/src/Gui/propertyeditor/PropertyItemDelegate.cpp index d548a745ae..ba10d2ef82 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.cpp +++ b/src/Gui/propertyeditor/PropertyItemDelegate.cpp @@ -58,7 +58,14 @@ void PropertyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & PropertyItem *property = static_cast(index.internalPointer()); if (property && property->isSeparator()) { - option.palette.setColor(QPalette::Text, option.palette.color(QPalette::BrightText)); + QColor color = option.palette.color(QPalette::BrightText); + QObject* par = parent(); + if (par) { + QVariant value = par->property("groupTextColor"); + if (value.canConvert()) + color = value.value(); + } + option.palette.setColor(QPalette::Text, color); option.font.setBold(true); option.state &= ~QStyle::State_Selected; } @@ -70,8 +77,14 @@ void PropertyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & option.state &= ~QStyle::State_HasFocus; if (property && property->isSeparator()) { - QBrush bg = option.palette.dark(); - painter->fillRect(option.rect, bg); + QBrush brush = option.palette.dark(); + QObject* par = parent(); + if (par) { + QVariant value = par->property("groupBackground"); + if (value.canConvert()) + brush = value.value(); + } + painter->fillRect(option.rect, brush); } QPen savedPen = painter->pen();