QPushButton; "Blurry" stylesheet for checked buttons



  • I have two buttons in a button group, and I want the checked button to have a blue background with white text, and the unchecked button white background with blue text.

    This my GUI setup:

        mvLBtn = new QPushButton("btn1");
        mvLBtn->setCheckable(true);
        mvLBtn->setChecked(true);
        mvMlBtn = new QPushButton("btn2");
        mvMlBtn->setCheckable(true);
    
        QWidget *mvGrp = new QWidget;
        QButtonGroup *mvBGp = new QButtonGroup;
        mvBGp->addButton(mvLBtn);
        mvBGp->addButton(mvMlBtn);
        QHBoxLayout *mvLayout = new QHBoxLayout;
        mvLayout->setMargin(0);
        mvLayout->setSpacing(0);
        mvLayout->addWidget(mvLBtn);
        mvLayout->addWidget(mvMlBtn);
        mvGrp->setLayout(mvLayout);
    

    This mvGrp widget is added the form later in a couple nested layouts.

    This is my stylesheet:

    this->setStyleSheet("QPushButton{margin: 0px; padding: 10px;}"
                            "QPushButton:checked{background-color: blue; color: white;}"
                            "QPushButton:!checked{background-color: white; color: blue;}");
    

    For some reason, the checked button (btn1) is blurry on the form.

    0_1531251405806_007d5f79-8959-4bb6-9389-4f71843ab9e8-image.png

    However, I've noticed that if I switch my stylesheet for checked vs !checked, the unchecked button does NOT have the same blurry affect.

    Switched stylesheet:

    this->setStyleSheet("QPushButton{margin: 0px; padding: 10px;}"
                           "QPushButton:checked{background-color: white; color: blue;}"
                           "QPushButton:!checked{background-color: blue; color: white;}");
    

    Form with btn1 checked:

    0_1531251472395_aa33ca8f-d668-4d36-a310-6b4bf81d2275-image.png

    How can I get my form to have a solid blue background on checked buttons?


Log in to reply
 

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