PDA

View Full Version : Will QPushButton::setChecked(true); change my Icon?



rawfool
19th June 2013, 10:45
I'm working on button properties similar to Start/Pause & Stop.
The scenario is like this:
1. Two Buttons: Start/Pause & Stop which is related to a process
2. On click of play, pause icon is shown and Stop button is enabled.
3. On click of pause, start icon is shown, and stop button is enabled.
4. I get one signal from other process - start: pause icon is shown & stop button should be enabled.

My button properties are like this


m_pbScan = new QPushButton(this);
m_pbScan->setIcon(QIcon(":/imgs/scanStart.png"));
m_pbScan->setCheckable(true);
connect(m_pbScan, SIGNAL(clicked(bool)), this, SLOT(onScanBtnClicked(bool)));

// SLOT:
void CStatusPage::onScanBtnClicked(bool click)
{
qDebug() << click;
if(click)
{
emit scanBtnClicked();
m_pbScan->setIcon(QIcon(":/imgs/scanPause.png"));
}
else
{
m_pbScan->setIcon(QIcon(":/imgs/scanStart.png"));
emit pauseBtnClicked();
}
m_pbScanStop->setEnabled(true);
}

When I get a signal from some other event promptin for start, then I'm calling this function -

void CStatusPage::scanOn()
{
m_pbScan->setChecked(true);
}

My doubt is, will the setChecked(true); automatically invoke connect and set icon to pauseIcon?
I trying to implement a logic that works with above mentioned scenarios.
Thank you.

Santosh Reddy
19th June 2013, 11:17
Use toggled() signal instead of clicked()

rawfool
19th June 2013, 11:40
Ok, and if I set the state of the button to m_pbScan->setChecked(true);, will it automatically call the onScanBtnClicked(bool click) slot ?
Thank you.

anda_skoa
19th June 2013, 14:41
The toggled signal is emitted whenever the checked state changes, no matter whether it was through user action or programmatic change.

Cheers,
_