Results 1 to 4 of 4

Thread: Will QPushButton::setChecked(true); change my Icon?

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Will QPushButton::setChecked(true); change my Icon?

    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
    Qt Code:
    1. m_pbScan = new QPushButton(this);
    2. m_pbScan->setIcon(QIcon(":/imgs/scanStart.png"));
    3. m_pbScan->setCheckable(true);
    4. connect(m_pbScan, SIGNAL(clicked(bool)), this, SLOT(onScanBtnClicked(bool)));
    5.  
    6. // SLOT:
    7. void CStatusPage::onScanBtnClicked(bool click)
    8. {
    9. qDebug() << click;
    10. if(click)
    11. {
    12. emit scanBtnClicked();
    13. m_pbScan->setIcon(QIcon(":/imgs/scanPause.png"));
    14. }
    15. else
    16. {
    17. m_pbScan->setIcon(QIcon(":/imgs/scanStart.png"));
    18. emit pauseBtnClicked();
    19. }
    20. m_pbScanStop->setEnabled(true);
    21. }
    To copy to clipboard, switch view to plain text mode 

    When I get a signal from some other event promptin for start, then I'm calling this function -
    Qt Code:
    1. void CStatusPage::scanOn()
    2. {
    3. m_pbScan->setChecked(true);
    4. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by rawfool; 19th June 2013 at 11:56.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Will QPushButton::setChecked(true); change my Icon?

    Use toggled() signal instead of clicked()
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (19th June 2013)

  4. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Will QPushButton::setChecked(true); change my Icon?

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Will QPushButton::setChecked(true); change my Icon?

    The toggled signal is emitted whenever the checked state changes, no matter whether it was through user action or programmatic change.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    rawfool (19th June 2013)

Similar Threads

  1. QPushButton::setEnabled( true ) not working
    By unshaven in forum Newbie
    Replies: 1
    Last Post: 9th August 2012, 07:27
  2. Replies: 1
    Last Post: 28th May 2010, 17:59
  3. QPushButton - Only show the Icon
    By graciano in forum Newbie
    Replies: 9
    Last Post: 19th September 2009, 22:15
  4. QPushButton Icon Image
    By QbelcorT in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 15:26
  5. setchecked( true) of the radio button doesn't work
    By richardander in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2009, 18:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.