Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: QPushButton Checked Change

  1. #21
    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

    Quote Originally Posted by wysota View Post
    Just please tell us what you want the HSPushButton class to do what QPushButton doesn't already do.
    I have many things (private variables, Painters etc... ) in HSPushButton if i use QPushButton toggled signal for each button i have to re-type these controls for each button its own event. If i override to toggled signal in my HSPushButton then emit a signal i don't need the check these conditions for each button. Totally i wanna hide these checks from programmers who will use my HSPushButton widget. thanks ...

  2. #22
    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

    Without being sure I would suggest that what you need is in your button's constructor to add
    Qt Code:
    1. connect(this,SIGNAL(toggled(bool)),this,SLOT(changedState(bool));
    To copy to clipboard, switch view to plain text mode 

    in your .cpp
    Qt Code:
    1. void HSPushButton::changedState(bool checked)
    2. {
    3. // do your checks here
    4. // and if necessary
    5. // emit (stateChanged(checked));
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. #23
    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

    Quote Originally Posted by nightroad View Post
    I have many things (private variables, Painters etc... ) in HSPushButton if i use QPushButton toggled signal for each button i have to re-type these controls for each button its own event.
    This suggests all those things should not be part of HSPushButton but rather some external class that does what is required upon receiving some signal from the button or some other place. Using QButtonGroup might be a good idea, something like:

    Qt Code:
    1. QButtonGroup *group = new QButtonGroup(this);
    2. group->setExclusive(...);
    3. QPushButton *button1 = new QPushButton(...); button1->setCheckable(true);
    4. QPushButton *button2 = new QPushButton(...); button2->setCheckable(true);
    5. QPushButton *button3 = new QPushButton(...); button3->setCheckable(true);
    6. group->addButton(button1, 1);
    7. group->addButton(button2, 2);
    8. group->addButton(button3, 3);
    9. connect(group, SIGNAL(buttonClicked(int)), this, SLOT(checkButton(int))); // or buttonChecked if exclusive
    10. // ...
    11. void X::checkButton(int which){
    12. switch(which) {
    13. case 1: ... ; break;
    14. case 2: ... ; break;
    15. case 3: ... ; break;
    16. // ...
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    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.


  4. #24
    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

    Thank you all guys ...

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.