Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

A stylesheet for each dialog



  • I use this function
    this->setStyleSheet
    to set the stylesheet. Is possible to have a different stylesheet for each dialog?
    Can you post an example?


  • Lifetime Qt Champion

    Hi,

    Yes, it's possible. However you don't tell it you want to change the style sheet for different dialogs classes or different instance of the same dialog class



  • Can you give me an example?
    In the main Form I call setStyleSheet() and the QButtons have the custom stylesheet.
    @#QFMainForm QPushButton:pressed {
    background: qradialgradient(cx: 0.4, cy: -0.1, fx: 0.4, fy: -0.1, radius: 1.35, stop: 0 #fff, stop: 1 #ddd);
    }@
    This stylesheet appears in the children dialogs.
    How can I have another QButton stylesheet for the children dialogs?


  • Lifetime Qt Champion

    Set another stylesheet on the dialog



  • It isn't a nice solution. Is necessary to replace all attributes.
    For example if in the main window I have
    @#QFMainForm QPushButton {
    color: white;
    font-size: 28px;
    }@

    and in the child dialog I have
    @#QFMainForm QPushButton {
    color: white;
    }@

    without attribute "font-size: 28px;", I will have the font size= 28 in the child dialog. To have the normal size I have to replace the font-size attribute too.
    Is there another way?


  • Lifetime Qt Champion

    Then make your stylesheet more specialized, by using e.g. object names


Log in to reply