Results 1 to 7 of 7

Thread: QDialogButtonBox Clicked Signals is called with other signals

  1. #1
    Join Date
    Jan 2014
    Posts
    9
    Qt products
    Platforms
    MacOS X Unix/X11

    Default QDialogButtonBox Clicked Signals is called with other signals

    Hi all, I am using PyQt.

    In my UI, I have created a QDialogButtonBox that houses 3 buttons - 'Add', 'Remove' and 'Clear' and I assigned their roles as follows:
    Qt Code:
    1. # List widget 01
    2. self.widget_01_btns = QtGui.QDialogButtonBox()
    3. self.widget_01_btns.addButton('Add', QtGui.QDialogButtonBox.AcceptRole)
    4. self.widget_01_btns.addButton('Remove', QtGui.QDialogButtonBox.RejectRole)
    5. self.widget_01_btns.addButton('Clear', QtGui.QDialogButtonBox.ResetRole)
    To copy to clipboard, switch view to plain text mode 

    As I will be having another same set of QDialogButtonBox, I thought it will be a good idea for them to 'share' the functions so that there is no need for me to write it twice.
    However when I tried to connect the signals, the signal assigned for 'Clear' will be called whenever either 'Add' or 'Remove' button is used.

    I tried another method that I found online, but upon using it, I got this error instead -
    `AttributeError: 'NoneType' object has no attribute 'clicked'`

    Qt Code:
    1. # For widget 01
    2. self.widget_01_btns.accepted.connect(lambda:self.add_objects(self.widget01_list))
    3. self.widget_01_btns.rejected.connect(lambda:self.remove_objects(self.widget01_list))
    4. # This is called in conjunction whenever either 'Add' or 'Remove' button is clicked
    5. self.widget_01_btns.clicked.connect(lambda:self.clear_objects(self.widget01_list))
    6.  
    7. # This is the online method I found but it is not working...
    8. # self.widget_01_btns.button(QtGui.QDialogButtonBox.Reset).clicked.connect(lambda:self.clear_objects(self.widget01_list))
    To copy to clipboard, switch view to plain text mode 


    Any pointers?

  2. #2
    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: QDialogButtonBox Clicked Signals is called with other signals

    If you are using Qt5 try

    Qt Code:
    1. self.widget_01_btns.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(lambda:self.clear_objects(self.widget01_list))
    To copy to clipboard, switch view to plain text mode 

    I.e. widgets moved into their own module in Qt5, called QtWidgets. They are no longer part of QtGui.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    9
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QDialogButtonBox Clicked Signals is called with other signals

    Quote Originally Posted by anda_skoa View Post
    If you are using Qt5 try

    Qt Code:
    1. self.widget_01_btns.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(lambda:self.clear_objects(self.widget01_list))
    To copy to clipboard, switch view to plain text mode 

    I.e. widgets moved into their own module in Qt5, called QtWidgets. They are no longer part of QtGui.

    Cheers,
    _
    Hi there, unfortunately I am still using PyQt4, and it is not working..

    I should have mentioned that
    Last edited by salik89; 16th March 2017 at 20:15.

  4. #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: QDialogButtonBox Clicked Signals is called with other signals

    Then one option might be to use the return value of addButton().

    Something like
    Qt Code:
    1. resetButton = self.widget_01_btns.addButton('Clear', QtGui.QDialogButtonBox.ResetRole)
    2. resetButton.clicked.connect(....);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Jan 2014
    Posts
    9
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QDialogButtonBox Clicked Signals is called with other signals

    Quote Originally Posted by anda_skoa View Post
    Then one option might be to use the return value of addButton().

    Something like
    Qt Code:
    1. resetButton = self.widget_01_btns.addButton('Clear', QtGui.QDialogButtonBox.ResetRole)
    2. resetButton.clicked.connect(....);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    This is working... Though it seems a bit pointless that I have to return it as I thought the use of roles in QDialogButtonBox is meant to reduce such work (correct me if I am wrong on this) but this is the impression I am getting...

  6. #6
    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: QDialogButtonBox Clicked Signals is called with other signals

    Using roles means the dialog button box can decide on the placement of buttons depending on the platform specific needs.
    I.e. you don't need to manually create and layout buttons.

    You can either connect to buttons explicitly or connect to the box signals.

    For the former it really doesn't matter if you connect to the button right after adding it or later retrieving it unless you require to connect later.

    Cheers,
    _

  7. #7
    Join Date
    Jan 2014
    Posts
    9
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: QDialogButtonBox Clicked Signals is called with other signals

    Quote Originally Posted by anda_skoa View Post
    Using roles means the dialog button box can decide on the placement of buttons depending on the platform specific needs.
    I.e. you don't need to manually create and layout buttons.

    You can either connect to buttons explicitly or connect to the box signals.

    For the former it really doesn't matter if you connect to the button right after adding it or later retrieving it unless you require to connect later.

    Cheers,
    _
    I was actually hoping that there is a signal for ResetRole, seeing that there are specific signals when using AcceptRole, RejectRole and HelpRole.
    Also I did not expected that when using `clicked`, it is being called in conjunction with the specific signals for the above 3 roles.

Similar Threads

  1. QComboBox Signals doesn't invoke the called function
    By ladiesfinger in forum Qt Programming
    Replies: 6
    Last Post: 30th December 2010, 17:20
  2. Replies: 1
    Last Post: 4th December 2010, 23:28
  3. Replies: 1
    Last Post: 24th October 2010, 12:09
  4. [SOLVED] Two signals emitted, only one slot called!
    By codeverse in forum Qt Programming
    Replies: 0
    Last Post: 11th August 2010, 16:46
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 23:18

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.