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



  • 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.



  • 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.



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



  • 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;
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.