0

I am using Qt 6.3 on Windows 11, and I am trying to figure out the current border color of QGroupBox in Fusion style.

I have subclassed QProxyStyle as my class GuiStyle, in my MainWindow constructor:

ui.setupUi(this);
auto guiStyle = new GuiStyle;
guiStyle->setBaseStyle(QStyleFactory::create("Fusion"));
qApp->setStyle(guiStyle);
qApp->setPalette(QPalette{QColor{0,0,0}});

My groupbox looks like this:

enter image description here

To figure out the current actual color of the border of QGroupBox I use QColorDialog and use the Pick Screen Color option then place my cursor exactly on top of the border of the QGroupBox. For different color of QPalette applied to QApplication I get different results:

  • qApp->setPalette(QPalette{QColor{0,0,0}}) => QColor(ARGB 1, 0.0901961, 0.0901961, 0.0901961)
  • qApp->setPalette(QPalette{QColor{10,10,10}}) => QColor(ARGB 1, 0.121569, 0.121569, 0.121569)
  • qApp->setPalette(QPalette{QColor{20,20,20}}) => QColor(ARGB 1, 0.152941, 0.152941, 0.152941)

Clearly, the border color of the QGroupBox is palette dependent. When I print out all colors of the current QPalette for each QPalette::ColorGroup and QPalette::ColorRole none of the color seems to match the current color which I get from the color picker of the QColorDialog. I tried to get all the values of the palette in the void GuiStyle::drawComplexControl function when the complex control is CC_GroupBox, in the void GuiStyle::drawPrimitive function when the primitive element is PE_Frame or PE_FrameGroupBox. But none of the colors seems to match the current border color of the QGroupBox. Is there any way I could determine this color programmatically?

康桓瑋
  • 33,481
  • 5
  • 40
  • 90
Chaitanya
  • 177
  • 2
  • 9

0 Answers0