Results 1 to 2 of 2

Thread: Multiple QPushButtons in widgets influence across widgets.

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple QPushButtons in widgets influence across widgets.

    Hi,

    I have created a ui file using Qt Designer, and here I've placed three qpushbuttons in a QGroupBox in one QGridLayout, and in another QGroupBox I've created three other QPushButtons.

    Inside GroupBox 1 the three qpushbuttons (pb1,pb2,pb3) are put in a vertical layout.
    Inside GroupBox 2 the other three qpushbuttons (pb4,pb5,pb6) are put in e.g qgridlayout

    pb1 and pb5 is active (setDown(true)) at initialization.
    So far so good.

    Intention on how it should work. Only one qpushbutton in a groupbox should be active (isDown() = true).
    So when I e.g click pb2, then pb2 is the only active pushbutton i groupbox1 that should be active. Leaving pushbuttons in Groupbox 2 as they are.

    But when I click pb2, I get strange behaviour. Clicking pb2 could give the following outcomes:
    * Cancels the active pb1, and setDown(true) on itself. => Correct
    * Cancels the active pb1, and setDown(true) on itself and on pb3.
    * Cancels the active pb1, and one of the above situations occur, but turning on and off pushbuttons on GroupBox2. Really not wanted.

    I've tried to counteract the misbehaviour inside the slot code as below:
    Qt Code:
    1. QPushButton* sender = dynamic_cast<QPushButton*>(QObject::sender());
    2. if (!v)
    3. return;
    4. if (sender == ui.pb1)
    5. {
    6. sender->setDown(v);
    7. sender->setChecked(true);
    8. ui.pb2->setDown(!v);
    9. ui.pb3->setDown(!v);
    10.  
    11.  
    12. }
    13. else if (sender == ui.pb2)
    14. {
    15. sender->setDown(v);
    16. ui.pb1->setDown(!v);
    17. ui.pb3->setDown(!v);
    18.  
    19. }
    20.  
    21. else if (sender == ui.pb3)
    22. {
    23. sender->setDown(v);
    24. ui.pb1->setDown(!v);
    25. ui.pb2->setDown(!v);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 


    But with no luck, it still change states of pushbuttons in the other groupbox.

    How can I stop the pushbuttons in one groupbox to influence other pushbuttons in the other groupboxes?

    I've tried to remorph GroupBoxes into QWidget, QFrame....but the problem are still there.

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

    Default Re: Multiple QPushButtons in widgets influence across widgets.

    Ever heard of a QButtonGroup? By the way, QGroupBox also has a button group functionality if you fill it with checkable buttons.
    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. Promoting to Multiple Custom Widgets
    By beginQT in forum Newbie
    Replies: 5
    Last Post: 21st October 2011, 10:45
  2. QScrollArea containing multiple widgets
    By Mercurial in forum Newbie
    Replies: 3
    Last Post: 4th February 2011, 10:08
  3. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  4. multiple Opengl Widgets:
    By manmohan in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2009, 05:06
  5. How to paint across/over multiple widgets?
    By richy in forum Qt Programming
    Replies: 3
    Last Post: 31st August 2006, 10:57

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.