QGroupBox title with two different colors (left half black, right half orange)
-
wrote on 28 Apr 2019, 11:08 last edited by
He fellow Qt devs,
How can I get the mentioned effect? To obtain a single title color is easy, either use palette-window text, or a style sheet...but I need two colors. Any hints?
-
hi
I don't think you can make it do so with a stylesheet.You most likely have to make your own custom GroupBox and paint it like that.
You might also be able via a QProxyStyle with an override for
drawItemTextas QGroupBox uses that for the text
proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
as seen here
https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#3787 -
wrote on 29 Apr 2019, 07:53 last edited by MasterBLB
I reimplemented whole MyGroupBox::paintEvent() copying the drawing code from CommonStyle into it, and using drawItemText twice. Anyway, thanks mate for correct hint!
WTF, why I can't mark @mrjj 's post as correct answer?? -
I reimplemented whole MyGroupBox::paintEvent() copying the drawing code from CommonStyle into it, and using drawItemText twice. Anyway, thanks mate for correct hint!
WTF, why I can't mark @mrjj 's post as correct answer??@MasterBLB said in QGroupBox title with two different colors (left half black, right half orange):
WTF, why I can't mark @mrjj 's post as correct answer??
Sadly, until we update to a newer version of the forum software, that option is not available for every user.
I'll set it as the correct answer for you.
1/4