Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Can we override the properties set through stylesheet ?
Forum Update on Monday, May 27th 2025

[SOLVED] Can we override the properties set through stylesheet ?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 7.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    Hi,

    I have a scenario where there is a list of widgets on a form, for all these widgets few properties like color/font has been set through a single stylesheet file (.qss). Now through a settings dialog can I change override the widget properties like font / foreground color / background color ? Or It will reflect always the properties as set in the stylesheet file ?

    Regards
    Sam

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      The last stylesheet line will override the previous ones if they affect the same properties.

      Just give it a try, you should be good.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        A test example to explain:

        I have a form with two pushButton , For the first button the font properties are set through stylesheet , when I click on the second button , there in the slot I set the font using QFont which doesn;t change anything.

        @/****BEGIN TEST ****/

        QFile file("C:/test/TestFont/style.qss");

        if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
        qDebug() << "Could not load file";
        else
        {
        QString StyleSheet = QLatin1String(file.readAll());
        ui->pushButton->setStyleSheet(StyleSheet);
        }

        /****END TEST ****/
        @

        SLOT:
        @void MainWindow::on_pushButton_2_clicked()
        {
        QFont font;
        font.setFamily("Arial");
        font.setPointSize(10);

        ui->pushButton->setFont(font);
        qDebug() << ui->pushButton->font();
        

        }@

        StyleSheet.qss
        @QPushButton#SomeButton
        {
        font-family: MS Outlook;
        font: bold 14px;
        }@

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          so you're not using a stylesheet in your slot

          What message does the qDebug in your slot give you?

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            Yes thats the question, If we can mix stylesheet properties and QFont/QPalette

            So if I set the same value using stylesheet then it works, but in this case I need to write a css file dynamically and force it to be used only for the specific module that uses it within the application.

            @QFont font;
            font.setFamily("Arial");
            font.setPointSize(20);

            ui->pushButton->setStyleSheet(QString("font-family: %1; font: %2px;").arg(font.family()).arg(font.pointSize()));@

            The idea is that we have a designer with a lot of widgets, somewhere there is a container/ list with some style define that can be edited by the user,

            So if I drag and drop a particular style to a widget the should be rendered/reflected by all the widgets which has the same type, eg a pushbutton.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              Implemented !

              Thanks Eddy

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                Yash
                wrote on last edited by
                #7

                Hi Sam , Please share how you achieved that.

                http://kineticwing.com : Web IDE, QSS Editor
                http://speedovation.com : Development Lab

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  Yash
                  wrote on last edited by
                  #8

                  Set font and refresh qss theme again. It works. Looks dirty but I think there is no right solution in such case.

                  Added info for future reference

                  http://kineticwing.com : Web IDE, QSS Editor
                  http://speedovation.com : Development Lab

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved