Results 1 to 5 of 5

Thread: QPalette help pls

  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QPalette help pls

    Hi,

    I have a widget whose constructor is something like this :

    Qt Code:
    1. pal.setBrush(QPalette::Window,QBrush(QPixmap(":/images/background.png")));
    2. setPalette(pal);
    3.  
    4. nameLabel = new QLabel(tr("Name"),this);
    5. nameLabel->setFont(QFont("Arial",9));
    6.  
    7. QIcon icon(":/images/plusbutton.png");
    8. addButton = new QPushButton(tr(""),this);
    9. addButton->setIcon(icon);
    10. addButton->setFlat(true);
    11. addButton->setFixedSize(20,20);
    12. connect(addButton,SIGNAL(pressed()),this,SLOT(addContact()));
    13.  
    14. QHBoxLayout *hLay = new QHBoxLayout;
    15. hLay->addSpacing(5);
    16. hLay->addWidget(nameLabel);
    17. hLay->addStretch(1);
    18. hLay->addWidget(addButton);
    19.  
    20. nameListWidget = new NameListWidget(c,this);
    21. connect(nameListWidget,SIGNAL(currentItemChanged(QListWidgetItem *,QListWidgetItem *)),
    22. this,SLOT(selectionChanged(QListWidgetItem *,QListWidgetItem *)));
    23. connect(nameListWidget,SIGNAL(clearContact()),this,SLOT(clearContact()));
    24.  
    25. //connect(nameListWidget,SIGNAL(currentRowChanged(int )),this,SLOT(selectionChanged(int )));
    26.  
    27. QVBoxLayout *mainLayout = new QVBoxLayout;
    28. mainLayout->setMargin(0);
    29. mainLayout->addSpacing(5);
    30. mainLayout->addLayout(hLay);
    31. mainLayout->addWidget(nameListWidget);
    32. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 

    The background is not changing though I have set the palette.

    Can someone please help ?
    Thanks a lot.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPalette help pls

    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette help pls

    Works. Thanx.

    But there is another problem. If you see in the code, I have a label and a button for which I am setting an icon and then resizing after making it flat.

    Everything on the label is fine. Label has the same backgound as the wiget.

    But there is a problem with the button because of the icon.
    The icon is not square and therefore the button's background is still gray.

    Can you please tell me how can I change this also like label's background ?

    Earlier I tried setting mask for the button, but it did not work.

    Thanks.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPalette help pls

    I think QPushButton uses a different color role for drawing it's background:

    From docs:
    QPalette::Button

    The general button background color. This background can be different from Window as some styles require a different background color for buttons.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPalette help pls

    I tried

    Qt Code:
    1. pal.setBrush(QPalette::Button,QBrush(QPixmap(":/images/background.png")));
    To copy to clipboard, switch view to plain text mode 

    But I cannot use this.

    Let me explain:

    The background is some kind of gradient and looks perfect for the label and the widget background.

    If I use the above code, buttons background will have some gradient which is not the way label's gradient looks like.

    Please look at the image attached. Please zoom it to get a clear picture.

    Please help
    Thanks.
    Attached Images Attached Images

Similar Threads

  1. QPalette help pls
    By munna in forum Qt Programming
    Replies: 7
    Last Post: 24th July 2006, 19:01
  2. QPalette won't set QLabel's Window & Foreground color
    By koklim in forum Qt Programming
    Replies: 6
    Last Post: 23rd January 2006, 10:27

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.