Results 1 to 5 of 5

Thread: System border color

  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default System border color

    Now I work on custom widget and I want to draw some element on it. Shortly, it looks like button.
    But I don't wont to use hardcoded color instead I want to draw it with system colors.
    I looked in documentation but did'nt found it.
    So how can I get system palette, or rather border color, like border color of QLineEdit?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: System border color

    For obtaining "system" palette use QApplication::palette. Also, take a look at QStyle, because this one is responsible for rendering widgets.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: System border color

    Yes, I know about QApplication:alette and also about QStyle. But i dind'nt found a way to obtain system color for borders

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: System border color

    Did you check how a button is rendered in QStyle?
    I guess you need QPalette::shadow.
    See, QWindowsStyle
    Qt Code:
    1. ...
    2. case PE_FrameDefaultButton: {
    3. QPen oldPen = p->pen();
    4. p->setPen(opt->palette.shadow().color());
    5. QRect rect = opt->rect;
    6. rect.adjust(0, 0, -1, -1);
    7. p->drawRect(rect);
    8. p->setPen(oldPen);
    9. break;
    10. }
    11. ...
    To copy to clipboard, switch view to plain text mode 
    .
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    May 2025
    Posts
    1
    Qt products
    Platforms
    Unix/X11 Android

    Default Re: System border color

    Quote Originally Posted by spirit View Post
    Did you check how a button is rendered in QStyle?
    I guess you need QPalette::shadow.
    See, QWindowsStyle
    Does this differ per QStyle, like https://discuss.kde.org/t/what-colou...julianlockhart alludes to? I ask because
    Qt Code:
    1. PyQt6.QtGui.QPen().setColor(PyQt6.QtGui.QColor(PyQt6.QtWidgets.QApplication.palette().color(PyQt6.QtGui.QPalette.ColorRole.Accent)))
    To copy to clipboard, switch view to plain text mode 
    gives me #000000 with
    Qt Code:
    1. plasma-breeze-qt6-6.3.5-1.fc42
    To copy to clipboard, switch view to plain text mode 
    .


    ** Moderator note: Use "CODE" not "ICODE" when enclosing code fragments. **
    Last edited by d_stranz; Today at 16:56. Reason: missing [code] tags
    When using a forum, remember to tag the person you are responding to, in case they are not subscribed to the thread.

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2013, 09:34
  2. Replies: 4
    Last Post: 8th September 2011, 08:22
  3. Replies: 1
    Last Post: 28th July 2010, 17:37
  4. How to set the BORDER COLOR of QDialog?
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2007, 16:09
  5. Setting QGraphicsItem setSelected border color
    By forrestfsu in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2006, 08:22

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
  •  
Qt is a trademark of The Qt Company.