Style sheet woes



  • Hi
    I have a style sheet that sets the background colour for QDialog -
    @
    QDialog {
    background-color: red;
    }
    @
    My application has a QListWidget added from Designer and is created with its containing layout as the parent,
    Upon selecting an element in the list I launch a dialog, but the style sheet is not applied to this dialog.
    I believe that this is because the list widget is not created with my main window as a parent

    I thought that by specifying the background colour in the style sheet that all dialogs (regardless of parent) would have the same background colour.

    I would be grateful if someone could explain why this is not the case

    Thanks in advance


  • Moderators

    Style information is propagated down the line: from parent to all children. If you create an unparented dialog, you need to set the stylesheet on it yourself.



  • Hi
    thanks for your quick response
    here is the code I use to create the dialog
    @
    UserInterface::SessionManagementUI::CreateSessionDialog dialog(this);
    @
    so I am creating it with a parent


  • Moderators

    Do you set that stylesheet on your whole application, or on a certain widget? Maybe the setStyleSheet() call is on a different branch of parent-child tree?



  • Hi
    I set the style sheet in the constructor of my main window -
    @
    QString style = "QDialog {background-color: red;}";
    qApp->setStyleSheet(style);
    @

    If I find the main window and use that as the parent then the dialog is displayed as expected -
    @
    QWidget*x = this->parentWidget();
    x = x->parentWidget();
    x = x->parentWidget();
    UserInterface::SessionManagementUI::CreateSessionDialog dialog(x);
    @


  • Moderators

    Ok, this seems like a bug then. Qt4 or 5?



  • I am using 5.0.2


  • Moderators

    Please test in Qt4 if possible, and "report it on Jira":https://qt-project.org/wiki/ReportingBugsInQt.


Log in to reply
 

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