Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: QPushButton Checked Change

  1. #1
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QPushButton Checked Change

    Hi there,

    I'm using QPushButton like a checkbox , so is there any event about Checked state changed in QPushButton thanks for your help.

  2. #2
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton Checked Change

    QPushButton::ischecked() function

  3. #3
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    isChecked() returns checked state of QPushButton. I wanna catch event everytime changed state of qpushbutton like checkboxs stateChanged(int ) event. thanks ...

  4. #4
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushButton Checked Change

    Hm... was looking through documentation found something called QWidget::changeEvent...

  5. #5
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    thx Archa4 but it's not for checked stateChanged ...

  6. #6
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change


  7. #7
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    Thanks Rhayader , I just override void QAbstractButton::toggled ( bool checked ) [signal] but it doesn't work, btw my buttons in QButtonGroup , but as document said it works in QButtonGroup but doesn't work as i said ...

  8. #8
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    You don't need to override the signal. It's a signal. Connect it to a Slot.

  9. #9
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton Checked Change

    http://www.qtcentre.org/faq.php?faq=qt_signalslot........... I think this will help you

  10. #10
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    i need to override for check something then i emit signal. samething actually (;, still doesn't work btw ...

    edit : I typed mistakely slot there ! so this is my mistake many people confused then
    Last edited by nightroad; 21st March 2011 at 10:05.

  11. #11
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushButton Checked Change

    You don't emit a slot.

    Connect the toggled signal to a slot and then check what you have to check ?

  12. #12
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton Checked Change

    Then include your codes in the another function and call Q_Emit, it will trigger it

  13. #13
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    Qt Code:
    1. class HSPushButton : public QPushButton
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. HSPushButton(QWidget *parent = 0);
    7. ~HSPushButton();
    8.  
    9. ...
    10.  
    11. private:
    12.  
    13. ...
    14.  
    15. signals:
    16. ...
    17. void stateChanged(bool state);
    18.  
    19. protected:
    20. virtual void toggled(bool checked);
    21. ...
    22. };
    23.  
    24. HSPushButton.cpp
    25.  
    26. void HSPushButton::toggled(bool checked)
    27. {
    28. emit (stateChanged(checked));
    29. }
    To copy to clipboard, switch view to plain text mode 

    so is it wrong ? I don't think so cuz i'm using escapePressed on my buttons with same method ...

  14. #14
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPushButton Checked Change

    I don't get what is your goal with your HSPushButton class. Can you give us more detail ?

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton Checked Change

    Yes, it is wrong. toggled() as already noted is a signal not a slot. You can't have two functions (a signal and a slot) with the same signature.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    Guyz anyway thanks for your help , i'm gonna make it with my own way =) . If i use toggled directly i have to check many thing for each buttons own event so that is crapy ... anyway Thanks all ...

  17. #17
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    I might be wrong but don't you just want to see which button has been clicked in QButtonGroup?
    And does not the signal buttonClicked( int id ) work for you? You can use that on the group rather than individual buttons...

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton Checked Change

    I'd rather say your approach makes it crappy. We don't know what you are doing but you're certainly having an incorrect approach. If you tell us what is the ultimate goal you wish to achieve maybe we'll be able to suggest a better solution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton Checked Change

    @ wysota i typed something wrong
    Quote Originally Posted by nightroad View Post
    i need to override for check something then i emit signal. samething actually (;, still doesn't work btw ...

    edit : I typed mistakely slot there ! so this is my mistake many people confused then

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushButton Checked Change

    Just please tell us what you want the HSPushButton class to do what QPushButton doesn't already do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Change Opacity of QPushButton
    By DiamonDogX in forum Qt Programming
    Replies: 3
    Last Post: 5th November 2010, 12:09
  2. How to show QPushButton as flat when it is checked
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2010, 10:07
  3. Change text in QPushButton?
    By bizmopeen in forum Newbie
    Replies: 4
    Last Post: 10th February 2010, 22:25
  4. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  5. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22

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.