QMainWindow Problem



  • In my application there are 3 windows: One Main Window, and two child windows.
    I am changing my main windows background color to white using setstylesheet..
    so this is also applying the same settings to my child windows, which I dont want..
    In one of my child windows there is a listview with scrollbar, they are also becoming white.
    so my question is how can I change my two child windows background settings to their default settings.

    Thanx in advance..



  • Please post your style sheet, how you set it and how you create your widgets. Somewhere in that, I assume, area is the bug.



  • @myWindow->setStyleSheet(QString::fromUtf8("background-color: rgb(254, 255, 247);"));@



  • @extension *e = new extension(this);
    e->setWindowModality(Qt::WindowModal);
    e->show();

    a = new ampstart(this);
    a->setWindowModality(Qt::WindowModal);
    a->show();
    @

    above is the way how I created my stylesheet, and the two child windows..



  • You need to use a more specific selector to ensure that only your QMainWindow selects that particular syle.

    Something like this stylesheet snippet should do it:

    @
    QMainWindow {
    background-color: rgb(254, 255, 247);
    }
    @

    You can set this directly on yoru mainwindow via the ui file. Just right-click on the main window in design mode of creator and select "Change Stylesheet..." and past the above in and hit Apply.



  • Yes, I agree with ZapB but I have one comment about the two child windows.
    It is not necessary to call show() explicitly for each child as they will be show when the parent window is visible.



  • [quote author="ZapB" date="1310040148"]You need to use a more specific selector to ensure that only your QMainWindow selects that particular syle.

    Something like this stylesheet snippet should do it:

    @
    QMainWindow {
    background-color: rgb(254, 255, 247);
    }
    @

    You can set this directly on yoru mainwindow via the ui file. Just right-click on the main window in design mode of creator and select "Change Stylesheet..." and past the above in and hit Apply.[/quote]

    The reason why this is needed is that style sheets are also derived / forwarded to shildren. And you set the properties in a generic way.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.