Results 1 to 3 of 3

Thread: reset the Palette of my QWidget

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question reset the Palette of my QWidget

    Hi everyone,

    For setting an image as the background image of my QWidget I am using the following code-

    Qt Code:
    1. this->setAutoFillBackground(true);
    2. QPalette palette = this->palette();
    3. palette.setBrush(this->backgroundRole(), QBrush(QImage("MyImage.jpg")));
    4. this->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    Now I want to reset my Palette and make my QWidget appear completely Black. How do I do that?
    I tried using
    QPixMap and QPixMap::fill(Qt::Black)
    and then setting this PixMap to my Palette, but it didn't work

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: reset the Palette of my QWidget

    If you haven't change the parent's palette, just take that, otherwise take the one from the QApplication instance

    Qt Code:
    1. setPalette(parentWidget()->palette());
    2. // or
    3. setPalette(QApplication::palette());
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    sattu (12th February 2014)

  4. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: reset the Palette of my QWidget

    Quote Originally Posted by anda_skoa View Post
    If you haven't change the parent's palette, just take that, otherwise take the one from the QApplication instance

    Qt Code:
    1. setPalette(parentWidget()->palette());
    2. // or
    3. setPalette(QApplication::palette());
    To copy to clipboard, switch view to plain text mode 
    _
    Sorry for replying late. For the moment what I did is I put a QFrame over the widget I wanted to appear black and made the background of the QFrame as black. So that solved the issue but yes, it's not a good way of doing it.
    So I will definitely try what you have written here and will get back if I face any issues.

    -Thanks,
    Sattu

Similar Threads

  1. Replies: 1
    Last Post: 19th March 2014, 22:25
  2. QDockWidget -> Reset all
    By pl01 in forum Qt Programming
    Replies: 2
    Last Post: 24th March 2011, 12:11
  3. Replies: 1
    Last Post: 9th February 2010, 12:11
  4. Bug in Qt4.3.3 QXmlSimpleReader::reset() ?
    By Shawn in forum Qt Programming
    Replies: 9
    Last Post: 3rd March 2008, 09:14
  5. How to reset the Palette for form
    By donmorr in forum Qt Tools
    Replies: 3
    Last Post: 12th August 2006, 12:14

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.