简体   繁体   中英

Qt Set background Color of QPushButton

I am very new to Qt and I am making some changes to a program. What I am trying to do is get a QPushButton called start_ to change its color when clicked. The button is declared here:

void StatusTab::CreateControlFrame() {
start_ = new QPushButton(tr("Start Capture"), this);
start_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
button_layout->addWidget(start_, 0, 0, 1, 1);
connect(start_, SIGNAL(clicked()), this, SLOT(OnStartClicked()));
}

I am guessing that the code needs to be added in the OnStartClicked() method but I am not sure what functions I need to use. Any help would be appreciated.

Have you tried Qt Designer, with which you can add widgets and adjust their apparence.conveniently. Qt provides QSS to Customize widgets. Examples .In this case, you can use

start_->setStyleSheet("QPushButton:pressed { \
    background-color: rgb(224, 0, 0);        \
    border-style: inset;                     \
}");

You can set QSS in Qt Designer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM