Results 1 to 4 of 4

Thread: Change ONLY the background color of a QFrame, not everything in it.

  1. #1
    Join Date
    Apr 2017
    Posts
    53
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Change ONLY the background color of a QFrame, not everything in it.

    I have a QFrame that I want to change the background color.

    I do so using the following:

    my_qframe->setStyleSheet("background-color:yellow;");

    Which works -- to a point

    I have several buttons in that frame. I do not want their colors changed, but they do change.

    Is there a way around this?

    Thank You

    emp1953

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Change ONLY the background color of a QFrame, not everything in it.

    Quote Originally Posted by emp1953 View Post
    I have a QFrame that I want to change the background color.
    ...
    Perhaps:
    Qt Code:
    1. my_qframe->setStyleSheet("QFrame { background-color:yellow; }");
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 9th January 2020 at 09:21.

  3. #3
    Join Date
    Apr 2017
    Posts
    53
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Change ONLY the background color of a QFrame, not everything in it.

    Quote Originally Posted by ChrisW67 View Post
    Perhaps:
    Qt Code:
    1. my_qframe->setStyleSheet("QFrame { background-color:yellow; }");
    To copy to clipboard, switch view to plain text mode 
    Thank you this worked perfectly. How do I mark this solved?


    Added after 13 minutes:


    chrisw67, It seems to work only if buttons are in the qframe. Some of the frames have listwidgets and they turn green and stay that way. Do I have to take an additional step and use a stylesheet to turn them back?
    Last edited by emp1953; 9th January 2020 at 18:46.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Change ONLY the background color of a QFrame, not everything in it.

    The list widget will not be going green because of the QFrame style above, which only mentions yellow. The QListWidget class inherits from QFrame so it can be affected by a style selector "QFrame". You can change that behaviour by changing the selector:
    Qt Code:
    1. my_qframe->setStyleSheet(".QFrame { background-color:yellow; }");
    To copy to clipboard, switch view to plain text mode 
    See Qt5 Style Sheet Syntax esp. under Selector Types heading.

    Where else are you applying style sheets? They cascade down to contained widgets, so it may be a parent widget with a style sheet that is driving this.

Similar Threads

  1. QFrame background color overpaints the content widgets
    By cranberries in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2015, 15:39
  2. How to change the color of background of QMainwindow?
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2012, 00:56
  3. Change frame background color
    By Ishmael in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 06:38
  4. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 08:14
  5. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 23:05

Tags for this Thread

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.