Pushbutton:checked stylesheet font ?



  • Applying this stylesheet has no effect to the font when toggling.
    What is wrong in this stylesheet or should i do a different way ?

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



  • 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



  • 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;
    }@



  • 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...



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



  • 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 :)



  • 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.



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



  • 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;
    }
    }
    }

    @



  • thank you ! i can learn from this code :)



  • 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 :)



  • 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.



  • 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.


Log in to reply
 

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