Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Retrieve the colours used by Qt to render a frame of StyledPanel shape
Forum Update on Monday, May 27th 2025

[SOLVED] Retrieve the colours used by Qt to render a frame of StyledPanel shape

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    agarny
    wrote on last edited by
    #1

    I have a widget of my own and I would like to ensure that the colours I use are consistent with the rest of the widgets I use in my Qt application. For what I am doing, I would need to retrieve the colours used by a frame which shape is set to QFrame::StyledPanel. On my copy of Windows 7, Qt renders the border of such a frame using a colour which RGB value is (130, 135, 144). Now, in my widget, I would like to use that colour, but I can't seem to be able to get it. I tried to get the colour from my widget's palette by using the color() function and passing to it different colour roles (QPalette::Window, QPalette::WindowText, etc.), but none of them gave me the RGB value used by Qt to render the frame above. So, what am I missing?...

    Cheers, Alan.

    1 Reply Last reply
    1
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Well you probably won't like the answer:
      QWindowsVistaStyle drops back to QCommonStyle for CE_ShapedFrame and QFrame::StyledPanel, which calls
      @drawPrimitive(QStyle::PE_Frame, ...)@

      on the widget's style (i.e. QWindowsVistaStyle) to draw the frame. QWindowsVistaStyle drops back to QWindowsXPStyle for PE_Frame which itself creates an XPThemeData object. Now the funny part: it's actually a part meant for Listviews that is drawn:
      @XPThemeData theme(0, 0, QLatin1String("LISTVIEW"), LVP_LISTGROUP, 0)@

      they get the color from this themedata object via
      @COLORREF bcRef;
      pGetThemeColor(theme.handle(), LVP_LISTGROUP, stateId, TMT_BORDERCOLOR, &bcRef);
      QColor bordercolor(qRgb(GetRValue(bcRef), GetGValue(bcRef), GetBValue(bcRef)));@

      where stateId is either ETS_NORMAL or ETS_DISABLED, depending on the enabled-state of the frame.

      As you can see, Qt compensates for the user-friendlyness of the frontend, in the backend ;)

      //EDIT: Ah yes, I forgot to mention. XPThemeData is defined in qwindowsxpstyle_p.h. the "_p" means we're doomed. It's a private API.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        agarny
        wrote on last edited by
        #3

        Ok, I can see that now. Well, you are correct: I don't like the answer, but thanks for it nonetheless.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          agarny
          wrote on last edited by
          #4

          Ok, for those interested, I have 'solved' my problem by doing the following:

          @static bool firstTime = true;
          static QColor borderColor = QColor();

          if (firstTime) {
          QFrame frame;
          QImage image = QImage(widget->size(),
          QImage::Format_ARGB32_Premultiplied);

          frame.setFrameShape(QFrame::StyledPanel);
          frame.render(&image);
          
          borderColor = QColor(image.pixel(0, 0));
          
          firstTime = false;
          

          }@

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved