1

I can use different colors used in a Qt application via QPalette to style widgets via qtstylesheets, e. g. something like background-color: palette(base). However, I didn't find the color used for drawing the border of some widgets like QGroupBox or QFrame.

It it possible to access this color (via QPalette?) as well for use in qtstylesheets widget styling?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Tobias Leupold
  • 1,512
  • 1
  • 16
  • 41
  • Strange! According to the source code, it should be `QPalette::WindowText`, but it does not work. – scopchanov Sep 16 '20 at 14:05
  • windowText represents the foreground/text color iirc – Tobias Leupold Sep 17 '20 at 10:22
  • `QFrame::paintEvent` calls [`QFrame::drawFrame`](https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qframe.cpp.html#_ZN6QFrame9drawFrameEP8QPainter), where [`QCommonStyle::drawControl`](https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#2352) is called with `QStyle::CE_ShapedFrame` as `element`. There we have `QPalette::ColorRole foregroundRole = QPalette::WindowText;`. Furthermore, the `QFrame::StyledPanel` case calls [`QCommonStyle::drawPrimitive`](https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#274) with `QStyle::PE_Frame` as `pe`. ... – scopchanov Sep 17 '20 at 12:20
  • ... There we have a call to `QCommonStyle::qDrawPlainRect` with `frame->palette.windowText().color()` as color. – scopchanov Sep 17 '20 at 12:22
  • The border color is definitely not the window text color though … e. g. using Breeze, the window text is black, and the borders are gray … – Tobias Leupold Sep 19 '20 at 08:27
  • Which OS do you use? – scopchanov Sep 19 '20 at 10:56
  • groupBox->setStyleSheet("QGroupBox {" "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF);" "border: 2px solid gray;" "border-radius: 5px;" "margin-top: 10ex;" "}" "QGroupBox::title {" "subcontrol-origin: margin;" "padding: 5 0px;" "}"); – Vahagn Avagyan Sep 19 '20 at 21:52
  • @user6528273 Linux, Windows and macOS ;-) It's a cross-platform project. – Tobias Leupold Sep 20 '20 at 06:31
  • 1
    In short, `QFrame` delegates the painting of its frame to a subclass of `QStyle`, which is different for each OS. Take a look at those suclasses and try to find how `QStyle::CE_ShapedFrame` is painted. – scopchanov Sep 20 '20 at 17:09
  • So, to answer the question: It's not a single color, but may be a more compilcated procedure and it's different for different OSs? And thus not possible as such? – Tobias Leupold Sep 21 '20 at 12:16

0 Answers0