Results 1 to 4 of 4

Thread: Problems connecting PushButtons

  1. #1
    Join Date
    Aug 2006
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems connecting PushButtons

    I im, as you probably will understand, really new to qt.

    Im trying to connec a couple of pushbuttons but cant get it to work.
    Lets say I have three buttons, now i them with setCheckabel(true), if I click one of the it shuld be checked but when I click another one the that was checked should uncheck and the new one should be checked.
    I have tried a couple of diffrent ways but I mostly get the message that slot doesnt exist.
    How do I do this?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problems connecting PushButtons

    Have a look at QButtonGroup. It solves your problem.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems connecting PushButtons

    Thanks!!
    Works like a charm : )

  4. #4
    Join Date
    Jul 2006
    Location
    Slovakia
    Posts
    17
    Thanks
    12
    Thanked 6 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems connecting PushButtons

    This might be also useful for you (complete app attached):

    Qt Code:
    1. myApp::myApp()
    2. {
    3.  
    4. setupUi(this);
    5.  
    6. int count;
    7. QWidget *widget;
    8. QPushButton *button;
    9.  
    10. count = splitter->count(); // number of buttons in splitter
    11. // splitter is filled with buttons in designer
    12.  
    13.  
    14. // connect them all
    15. for(int i=0;i<count;i++)
    16. {
    17. widget = splitter->widget(i);
    18. button = (QPushButton*) widget;
    19. connect( button, SIGNAL( toggled(bool) ), this, SLOT( checkUncheck() ) );
    20. }
    21.  
    22. }
    23.  
    24.  
    25. void myApp::checkUncheck() // slot
    26. {
    27. int count, index;
    28. QObject *obj;
    29. QPushButton *button, *tmpButton;
    30. QWidget *widget;
    31.  
    32. count = splitter->count();
    33.  
    34. obj = sender();
    35. button = qobject_cast<QPushButton *>(obj);
    36.  
    37. index = splitter->indexOf(button);
    38.  
    39.  
    40. // if state not checked - return (we just unchecked button)
    41. if (button->isChecked() == false) return;
    42.  
    43.  
    44. for(int i=0;i<count;i++)
    45. {
    46. if ( i == index ) continue; // we skip current button
    47.  
    48. widget = splitter->widget(i);
    49. tmpButton = (QPushButton*) widget;
    50.  
    51. if (tmpButton->isChecked() == true) tmpButton->setChecked ( false );
    52. }
    53.  
    54. }
    To copy to clipboard, switch view to plain text mode 

    Note: I don't see QButtonGroup in designer (4.2.0-tp1)
    Attached Files Attached Files

Similar Threads

  1. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 16:39

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.