Results 1 to 5 of 5

Thread: How to change the color of background of QMainwindow?

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    176
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the color of background of QMainwindow?

    When I create a QMainwindow only(that is ,there is no DockWidget,no central Widget),and the main area color is grey,how to change it to other color ,such as white?


    Added after 8 minutes:


    shows as picture.
    windows.jpg
    Last edited by weixj2003ld; 5th July 2012 at 10:56.

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

    Default Re: How to change the color of background of QMainwindow?

    Qt Code:
    1. m.setStyleSheet("QMainWindow {background: 'yellow';}");
    2. m.show();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the color of background of QMainwindow?

    Did you try subclassing QMainWindow's paintEvent?

  4. #4
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    176
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change the color of background of QMainwindow?

    Quote Originally Posted by ChrisW67 View Post
    Qt Code:
    1. m.setStyleSheet("QMainWindow {background: 'yellow';}");
    2. m.show();
    To copy to clipboard, switch view to plain text mode 
    It can change the background color of QMainWindow,but it change the background color of Tool bar and status,too.

    Quote Originally Posted by Krump Lee View Post
    Did you try subclassing QMainWindow's paintEvent?
    I have subclassed QMainWindow's paintEvent,but I'm sorry how to do in it?

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

    Default Re: How to change the color of background of QMainwindow?

    What you want is to change the background of the centralWidget of the main window.
    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.


Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Replies: 1
    Last Post: 17th August 2010, 16:17
  3. Change frame background color
    By Ishmael in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 05:38
  4. how to change background color of QMenu??
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2009, 12:41
  5. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05

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.