Results 1 to 20 of 24

Thread: Retrieve the colours used by Qt to render a frame of StyledPanel shape

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

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

  2. #2
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    Hi,

    depending on the style, not everything is drawn by Qt itself, but by the native style engine. So some Colors etc. are impossible to get.
    I had the same issue as you and tried just letting the style draw the frame, which worked fine. But as I only needed part of a frame, I just used the color you mentioned to draw the frame myself.
    I guess those are your two options as well

  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    Well, at this stage, I just need to use the colour I mentioned (even though I would like a more general approach to my problem, if possible), so how did you get it in the end?

  4. #4
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    I just took a look at the code, as I still would like to get that color as well. But as I said, the frame is drawn by the windows style engine. So no chance getting the color.
    As I said, I just draw the frame with the color you mentionend myself.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    I don't know what you want to do with that color exactly, but with QStylePainter (or QStyle direct) you can draw frames etc. according to the current style.

  6. #6
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    Quote Originally Posted by ChiliPalmer View Post
    As I said, I just draw the frame with the color you mentionend myself.
    Ah, so you are really using (130, 135, 144)...?! Ok, that's not something I want to do. I want my applicaiton to be able to respond to a change of system colour theme, if needed.

    Quote Originally Posted by Lykurg View Post
    I don't know what you want to do with that color exactly, but with QStylePainter (or QStyle direct) you can draw frames etc. according to the current style.
    I just want to be able to use the colour used by Qt to render other widgets, so that it's all consistent colour wise. Anyway, I have never tried QStylePainter, so I will have a look at it, thanks.

  7. #7
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

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

    Qt Code:
    1. static bool firstTime = true;
    2. static QColor borderColor = QColor();
    3.  
    4. if (firstTime) {
    5. QFrame frame;
    6. QImage image = QImage(widget->size(),
    7. QImage::Format_ARGB32_Premultiplied);
    8.  
    9. frame.setFrameShape(QFrame::StyledPanel);
    10. frame.render(&image);
    11.  
    12. borderColor = QColor(image.pixel(0, 0));
    13.  
    14. firstTime = false;
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by agarny; 29th March 2012 at 12:19.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    What if the pixel happens to be transparent in this particular theme? What if the user changes the theme during the life of the program? What if...?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    Quote Originally Posted by wysota View Post
    What if the pixel happens to be transparent in this particular theme? What if the user changes the theme during the life of the program? What if...?
    I complete agree that this is not perfect, hence my use of single quotes around my use of "solved". So, if anyone has a better solution, then please feel free to share it with me. In fact, I just wish that Qt would provide us with more information about the colour scheme used to render various widgets.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    Qt doesn't have anything to do with this. It's not Qt that renders the theme on Windows Vista and up. You can probably use the native API to ask for that colour if the theming API supports it. Qt reports all it can in QPalette. If the colour you are looking for is not there then all that is left is Windows theming API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Retrieve the colours used by Qt to render a frame of StyledPanel shape

    I appreciate that Qt has nothing to do with it, but all I am trying to do is to have my widget using colours that are consistent with the other widgets that are (indirectly) rendered by Qt. Also, I want this to work on Windows, Linux and Mac OS X. So, for now, the solution I have is far from perfect, but it's still better than nothing (I could however improve it to at least address the change of theme during the life of the application).

Similar Threads

  1. QGLWidget render or QGraphicsView with GL viewport render
    By QTInfinity in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 11:34
  2. Replies: 1
    Last Post: 13th March 2008, 07:19
  3. Change the shape of a frame.
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 06:40
  4. QLabel colours
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 16:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.