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. Pushbutton:checked stylesheet font ?
Forum Updated to NodeBB v4.3 + New Features

Pushbutton:checked stylesheet font ?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 7.2k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    clochydd
    wrote on last edited by
    #2

    Hi wally123, I toggle the stylesheet of a pushButton like that:
    @
    // Bold + colour:
    pushV[i]->setStyleSheet("QPushButton {background-color: #C0BBFE; font: bold }");
    // Normal:
    pushV[i]->setStyleSheet("QPushButton {font: normal}");
    @
    and this works with size etc. as well

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deleted28
      wrote on last edited by
      #3

      the below code works except the font and font-size .
      i test in a fresh default qt gui application.
      maybe another property interferes (?)

      @QPushButton {
      color: blue;
      background-color: yellow;
      font: normal;
      font-size: 14pt;
      }
      QPushButton:checked {
      color: yellow;
      background-color: blue;
      font: bold;
      font-size: 36pt;
      }@

      1 Reply Last reply
      0
      • C Offline
        C Offline
        clochydd
        wrote on last edited by
        #4

        I've just tested it in my application like that:
        @
        if (bNormal) {
        pushV[i]->setStyleSheet("QPushButton {background-color: yellow; font: normal 7pt "Ubuntu"}");
        } else {
        pushV[i]->setStyleSheet("QPushButton {background-color: blue; font: bold 10pt "Ubuntu"}");
        }
        @
        and it works.
        Funny enough I could only modify the font if I use exactly this syntax...

        1 Reply Last reply
        0
        • C Offline
          C Offline
          clochydd
          wrote on last edited by
          #5

          and toggling the color works, too:
          @
          pushV[i]->setStyleSheet("QPushButton {color: yellow; background-color: blue; font: bold 10pt "Ubuntu"}");
          @

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted28
            wrote on last edited by
            #6

            the font part does not work here, there must be some
            other thing i do not take care and do not know yet.

            The problem is only the font setting in QPushButton:checked {}
            The "unchecked" part works.

            @QPushButton {
            color: blue;
            background-color: yellow;
            font: 14pt "Sans Serif";
            }
            QPushButton:checked {
            color: yellow;
            background-color: blue;
            font: 75 24pt "Sans Serif";
            }@

            amyway, thx for reply :)

            1 Reply Last reply
            0
            • C Offline
              C Offline
              clochydd
              wrote on last edited by
              #7

              Sorry, wally123, I did not recognize that you tried to use the Checked pushButton!
              I did not succeed to toggle the font with the Checked button and the behaviour was strange, when using a group of Checked Buttons. So I decided to simulate the Checked property with styleSheet and it works perfectly now.
              I fear, there's a bug in the the pushButton's Checked property, but I do not have enough facts yet.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                deleted28
                wrote on last edited by
                #8

                i also use it in a groupbox to display state of digital lines.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  clochydd
                  wrote on last edited by
                  #9

                  this is how I manage to make it work:
                  I put the buttons in a frame which has a stylesheet for the buttons.
                  In the code I assign the buttons to a QList pushV which makes it easier to toggle the buttons in f_pushV.

                  @
                  // styleSheet of QFrame fmPush, containing the buttons:
                  QPushButton {
                  font: 7pt "Ubuntu";
                  border-width: 1px;
                  border-color: #9187FF;
                  border-style: solid;
                  border-radius: 2;
                  min-width: 55px;
                  min-height: 17px;
                  }

                  QPushButton:hover {
                  background-color: plum;
                  }

                  QPushButton:pressed {
                  padding-left: 2px;
                  padding-top: 2px;
                  background-color: orchid;
                  }

                  // define a QList to represent the buttons:
                  QList<QPushButton *> pushV;

                  // define the size of QList pushV:
                  pushV = ui->fmPush->findChildren<QPushButton *>();

                  // assign the pushButtons to the elements of the QList:
                  for( i = 0; i < pushV.count(); ++i )
                  {
                  pushV[i] = ui->fmPush->findChild<QPushButton *>("pushV" + QString::number(i).rightJustified(2, '0'));
                  pushV[1]->setProperty("chk", 0);
                  }

                  // toggle buttons:
                  void MainProg::f_pushV()
                  {
                  QPushButton* b = qobject_cast<QPushButton*>(sender());
                  for (int i = 0; i < pushV.size(); ++i) {
                  if (pushV.at(i) == b) {
                  if (pushV[i]->property("chk") == 1) {
                  pushV[i]->setStyleSheet("QPushButton {color: blue; background-color: yellow; font: normal 7pt "Ubuntu"}"); //test
                  pushV[i]->setProperty("chk", 0);
                  } else {
                  pushV[i]->setStyleSheet("QPushButton {color: yellow; background-color: blue; font: bold 10pt "Ubuntu"}"); //test
                  pushV[i]->setProperty("chk", 1);
                  }
                  break;
                  }
                  }
                  }

                  @

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deleted28
                    wrote on last edited by
                    #10

                    thank you ! i can learn from this code :)

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      deleted28
                      wrote on last edited by
                      #11

                      wow, its very interesting!
                      it's possible to see more ?

                      I have a bunch of open QSerialports and sending a ping to all and then want to know which port
                      response to the ping. All readyRead SIGNALS are connected to a single SLOT.
                      I can do some polling to figure this out, but when the responding port is identified i need
                      to connect SIGNAL/ SLOT dynamically. The code above "smells" like a solution :)

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        clochydd
                        wrote on last edited by
                        #12

                        It depends on what you are interested in: I've started to work with Qt only a few months ago and I'm now in the process of rewriting my database/ERP applications with Qt/C++. I'm in qt-project forum very frequently and it's my pleasure if I can help.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          deleted28
                          wrote on last edited by
                          #13

                          ok, i'll be back when i'm able to ask a precise question.
                          For now it's little foggy yet, i started few weeks ago.

                          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