Results 1 to 4 of 4

Thread: background color of a MainWindow

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default background color of a MainWindow

    Hi,
    How can I set the background color as black of a MainWindow? Please help me!!!!!!!!!
    Sabeesh

  2. #2
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: background color of a MainWindow

    This code generated from Qt Designer,
    Qt Code:
    1. QPalette palette;
    2. QBrush brush(QColor(255, 255, 255, 255));
    3. brush.setStyle(Qt::SolidPattern);
    4. palette.setBrush(QPalette::Active, QPalette::Base, brush);
    5. QBrush brush1(QColor(0, 0, 0, 255));
    6. brush1.setStyle(Qt::SolidPattern);
    7. palette.setBrush(QPalette::Active, QPalette::Window, brush1);
    8. palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
    9. palette.setBrush(QPalette::Inactive, QPalette::Window, brush1);
    10. palette.setBrush(QPalette::Disabled, QPalette::Base, brush1);
    11. palette.setBrush(QPalette::Disabled, QPalette::Window, brush1);
    12. Dialog->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    Dialog - it's your MainWindow.

    I think, this code is possible to optimize.

  3. #3
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: background color of a MainWindow

    try this in your mainwindow class constructor:
    tested code:
    Qt Code:
    1. QPalette palette;
    2. palette.setColor(backgroundRole(), Qt::black);
    3. setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to rajesh for this useful post:

    sabeesh (25th July 2007)

  5. #4
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: background color of a MainWindow

    Hi,
    Thankyou
    it's working

    Sabeesh

Similar Threads

  1. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  2. Replies: 1
    Last Post: 5th April 2006, 16:44

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.