Reputation: 469
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.
Upvotes: 1
Views: 3608
Reputation: 5530
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.
Upvotes: 3