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. Problem of style sheet when a part is in a QSS file and another part set by setStyleSheet
QtWS25 Last Chance

Problem of style sheet when a part is in a QSS file and another part set by setStyleSheet

Scheduled Pinned Locked Moved Solved General and Desktop
qt 5.6.3qsssetstylesheet
4 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    Alain38 0
    wrote on last edited by
    #1

    Hi,
    In a QSS file, used at application level, I'm setting rules to display QToolButton. On of these rules is:

    QToolButton:checked
    {
        border: 2px solid #867692;
    }
    

    Now, I have one QToolButton that should use this rule. But it must also be displayed with a specific background color. This color is determined programatically. So, I tried to set it by using

    myToolButton->setStyleSheet(...)
    

    Whatever the string I'm using in setStyleSheet, the rule in the QSS file is no more applied. I tried "background-color: mycolor;", "QToolButton {bacground-color: myColor;}", ...

    Any idea on how to solve this problem?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please show the stylesheet you are using for your button.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Please show the stylesheet you are using for your button.

        A Offline
        A Offline
        Alain38 0
        wrote on last edited by
        #3

        Hi @SGaist,
        It is what I have written in my post. To be more precise all QToolButton have a border of a given color when they are checked (if they are checkable obviously), and no border if they are not checked. Border, and border color must be set by the QSS file to be able to be changed easily. And, usually they are also in a constant background color.

        But, this specific QToolButton must have a specific background color. And this color depends of an internal configuration of the application. This is why I'm trying to set it by setStyleSheet. Without the setStyleSheet, this button follows the rules defined in the QSS. But, with the setStyleSheet it is not the case (I always have a button with the right background but without the border when checked).

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alain38 0
          wrote on last edited by
          #4

          Ok,
          I found the bullshit. My first try was setStyleSheet("background-color: myColor;"). As it did not work (no border when checked), I tried after setStyleSheet("QToolButton {background-color: myColor;}"). As it was still the same shit, and as the documentation recommends to set the border, I have moved to setStyleSheet("QToolButton {background-color: myColor; border:none;}") (as in the QSS file). And all the following tries were with "border:none" on the rule without the :checked modifier.

          Suprisingly, without the definition of the border in the setStyleSheet everything works well. So I have the border defined in the QSS file (as from the beginning). And in the program I have:

          currentBtn  ->setStyleSheet(QString("QToolButton#BooleanObject {background-color: %1;} QToolButton#BooleanObject:checked {background-color:%1;}").arg(myColor.name()));
          

          This is a really strange behavior. But, long time ago, I have understood that I will never understand the "logic" of the QT style sheet.

          1 Reply Last reply
          1

          • Login

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