Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, February 2007
Re: The case of the disappearing widget - possible workaround


Message 1 in thread

>On Tuesday 27 February 2007 14:35, Susan Macchia wrote:
>> I am having some trouble displaying plain QWidget with a color as a child
>> of another.  Below is a simple reproducer of the problem (a test program I
>> created):
>>
>> class MyWin: public QWidget
>> {
>>     Q_OBJECT
>>
>> public:
>>     MyWin(QWidget *parent = NULL)
>>
>>         QWidget(parent)
>>     {
>>         QPalette palette;
>>         palette.setColor(QPalette::Window, QColor("white"));
>>         palette.setColor(QPalette::WindowText, QColor("black"));
>>         setPalette(palette);
>>         resize(300, 300);
>>
>>
>>         QWidget *wid= new QWidget(this);
>>
>>         palette = wid->palette();
>>         palette.setColor(QPalette::Window,     QColor("red"));
>>         palette.setColor(QPalette::WindowText, QColor("white"));
>>         wid->setPalette(palette);
>>         wid->resize(100, 100);
>>         wid->move(20, 20);
>>
>>         QLabel *label = new QLabel("This is a label", wid);
>>         label->move(2, 2);
>>     }
>> };
>>
>>
>>
>> The second QWidget briefly flashes, then disappears... Why?
>>
>> Below is main:
>>
>> int main(int argc, char **argv)
>> {
>>     QApplication app(argc, argv);
>>
>>     MyWin win;
>>     win.show();
>>     return app.exec();
>> }
>>
>>
>>
>>
>> Thanks in advance,
>> Susan

Ok, now I have tried every conceiveable palette setting for the second widget (wid) and it still disappears.  Furthermore, if instead of setting specific palette colors for specific roles I do the following:
    wid->setPalette(QPalette(QColor("red")));
The widget shows up but takes on the colors of the parent.  Essentially, this setting of the color is completely ignored (and in the Qt doc, since this is considered the "button" color, that could be why.

However, if instead of setting the palette for "wid" I do the following:
        QString styleSheet = "QWidget \
        {  \
            background-color:           red; \
            color:                      white; \
        }";        
        wid->setStyleSheet(styleSheet);

The widget gets the right colors, but the downside is that I lost the "platform" style for controls (i.e., it is no longer plastique).  Even passing -style on the command line doesn't apply the right style.  

I think there are definite bugs here.  If anyone has more experience with this area, could you tell me whether I should submit a bug report to Trolltech?

Thanks,
Susan






Message 2 in thread

You might need to call setAutoFillBackground(true) on your widgets.

By default in Qt >4.1 children get a snapshot of their parents for their 
background. True transparency. There is no fill at all with the palette 
background color.  To get a default fill then call 
setAutoFillBackground(true) on your widgets.

--Justin

Susan Macchia wrote:
>
> >On Tuesday 27 February 2007 14:35, Susan Macchia wrote:
> >> I am having some trouble displaying plain QWidget with a color as a 
> child
> >> of another.  Below is a simple reproducer of the problem (a test 
> program I
> >> created):
> >>
> >> class MyWin: public QWidget
> >> {
> >>     Q_OBJECT
> >>
> >> public:
> >>     MyWin(QWidget *parent = NULL)
> >>
> >>         QWidget(parent)
> >>     {
> >>         QPalette palette;
> >>         palette.setColor(QPalette::Window, QColor("white"));
> >>         palette.setColor(QPalette::WindowText, QColor("black"));
> >>         setPalette(palette);
> >>         resize(300, 300);
> >>
> >>
> >>         QWidget *wid= new QWidget(this);
> >>
> >>         palette = wid->palette();
> >>         palette.setColor(QPalette::Window,     QColor("red"));
> >>         palette.setColor(QPalette::WindowText, QColor("white"));
> >>         wid->setPalette(palette);
> >>         wid->resize(100, 100);
> >>         wid->move(20, 20);
> >>
> >>         QLabel *label = new QLabel("This is a label", wid);
> >>         label->move(2, 2);
> >>     }
> >> };
> >>
> >>
> >>
> >> The second QWidget briefly flashes, then disappears... Why?
> >>
> >> Below is main:
> >>
> >> int main(int argc, char **argv)
> >> {
> >>     QApplication app(argc, argv);
> >>
> >>     MyWin win;
> >>     win.show();
> >>     return app.exec();
> >> }
> >>
> >>
> >>
> >>
> >> Thanks in advance,
> >> Susan
>
> Ok, now I have tried every conceiveable palette setting for the second 
> widget (wid) and it still disappears.  Furthermore, if instead of 
> setting specific palette colors for specific roles I do the following:
>     wid->setPalette(QPalette(QColor("red")));
> The widget shows up but takes on the colors of the parent.  
> Essentially, this setting of the color is completely ignored (and in 
> the Qt doc, since this is considered the "button" color, that could be 
> why.
>
> However, if instead of setting the palette for "wid" I do the following:
>         QString styleSheet = "QWidget \
>         {  \
>             background-color:           red; \
>             color:                      white; \
>         }";      
>         wid->setStyleSheet(styleSheet);
>
> The widget gets the right colors, but the downside is that I lost the 
> "platform" style for controls (i.e., it is no longer plastique).  Even 
> passing -style on the command line doesn't apply the right style. 
>
> I think there are definite bugs here.  If anyone has more experience 
> with this area, could you tell me whether I should submit a bug report 
> to Trolltech?
>
> Thanks,
> Susan
>
>

begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard


Message 3 in thread

Yahoo - that worked. THANK YOU!

-- Susan

----- Original Message ----
From: Justin Noel <justin@xxxxxxx>
To: qt-interest@xxxxxxxxxxxxx
Sent: Wednesday, February 28, 2007 11:47:16 AM
Subject: Re: The case of the disappearing widget - possible workaround


You might need to call setAutoFillBackground(true) on your widgets.

By default in Qt >4.1 children get a snapshot of their parents for their 
background. True transparency. There is no fill at all with the palette 
background color.  To get a default fill then call 
setAutoFillBackground(true) on your widgets.

--Justin

Susan Macchia wrote:
>
> >On Tuesday 27 February 2007 14:35, Susan Macchia wrote:
> >> I am having some trouble displaying plain QWidget with a color as a 
> child
> >> of another.  Below is a simple reproducer of the problem (a test 
> program I
> >> created):
> >>
> >> class MyWin: public QWidget
> >> {
> >>     Q_OBJECT
> >>
> >> public:
> >>     MyWin(QWidget *parent = NULL)
> >>
> >>         QWidget(parent)
> >>     {
> >>         QPalette palette;
> >>         palette.setColor(QPalette::Window, QColor("white"));
> >>         palette.setColor(QPalette::WindowText, QColor("black"));
> >>         setPalette(palette);
> >>         resize(300, 300);
> >>
> >>
> >>         QWidget *wid= new QWidget(this);
> >>
> >>         palette = wid->palette();
> >>         palette.setColor(QPalette::Window,     QColor("red"));
> >>         palette.setColor(QPalette::WindowText, QColor("white"));
> >>         wid->setPalette(palette);
> >>         wid->resize(100, 100);
> >>         wid->move(20, 20);
> >>
> >>         QLabel *label = new QLabel("This is a label", wid);
> >>         label->move(2, 2);
> >>     }
> >> };
> >>
> >>
> >>
> >> The second QWidget briefly flashes, then disappears... Why?
> >>
> >> Below is main:
> >>
> >> int main(int argc, char **argv)
> >> {
> >>     QApplication app(argc, argv);
> >>
> >>     MyWin win;
> >>     win.show();
> >>     return app.exec();
> >> }
> >>
> >>
> >>
> >>
> >> Thanks in advance,
> >> Susan
>
> Ok, now I have tried every conceiveable palette setting for the second 
> widget (wid) and it still disappears.  Furthermore, if instead of 
> setting specific palette colors for specific roles I do the following:
>     wid->setPalette(QPalette(QColor("red")));
> The widget shows up but takes on the colors of the parent.  
> Essentially, this setting of the color is completely ignored (and in 
> the Qt doc, since this is considered the "button" color, that could be 
> why.
>
> However, if instead of setting the palette for "wid" I do the following:
>         QString styleSheet = "QWidget \
>         {  \
>             background-color:           red; \
>             color:                      white; \
>         }";      
>         wid->setStyleSheet(styleSheet);
>
> The widget gets the right colors, but the downside is that I lost the 
> "platform" style for controls (i.e., it is no longer plastique).  Even 
> passing -style on the command line doesn't apply the right style. 
>
> I think there are definite bugs here.  If anyone has more experience 
> with this area, could you tell me whether I should submit a bug report 
> to Trolltech?
>
> Thanks,
> Susan
>
>


begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard