Results 1 to 3 of 3

Thread: QPushButton State (in PyQt) ?

  1. #1
    Join Date
    Dec 2014
    Posts
    48
    Thanks
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QPushButton State (in PyQt) ?

    A push button is checkable (setCheckable(True)), and when it is checked - a method is called to establish a [bool=True] value. If I manually uncheck (2nd click) the button, [bool=False] <<=ideally.

    Unfortunately, the second check merely reinstates the [bool=True] value. Is there any means of checking the state of a button, ergo; if-down = return True, if-up = return False?

    Relevant code:
    Qt Code:
    1. ...
    2. self.pushButtonSetBase.setCheckable(True)
    3. self.pushButtonSetBase.toggled.connect(self.on_pushButtonSetBase_toggled)
    4.  
    5. ...
    6.  
    7. @QtCore.pyqtSlot()
    8. def on_pushButtonSetBase_toggled(self):
    9. if self.pushButtonSetBase.isChecked:
    10. print 'update the base!'
    11. self.rowOverride = True
    12. elif not self.pushButtonSetBase.isChecked:
    13. print 'no base updates allowed!'
    14. self.rowOverride = False
    15. ...
    To copy to clipboard, switch view to plain text mode 

    Probably a simple solution - but seems to be a struggle @ current.
    Thousand thanks.

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    Added after 23 minutes:


    UPDATE:
    This pyQt business is tricky... and fun.
    Here is the working solution for anyone interested in the future.

    Qt Code:
    1. ...
    2. self.pushButtonSetBase.setCheckable(True)
    3. self.pushButtonSetBase.toggled.connect(self.on_pushButtonSetBase_toggled)
    4. ...
    5. @QtCore.pyqtSlot(bool) #<<== the missing link
    6. def on_pushButtonSetBase_toggled(self,checked):
    7. if checked:
    8. print 'update the base!'
    9. self.rowOverride = True
    10. elif not checked:
    11. print 'no base updates allowed!'
    12. self.rowOverride = False
    13. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by jkrienert; 20th January 2015 at 14:37.

  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: QPushButton State (in PyQt) ?

    You can just use an else on the second branch, the boolean value can only be true or false.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    48
    Thanks
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Default Re: QPushButton State (in PyQt) ?

    What about the super-position?

Similar Threads

  1. Change state property within a current state?
    By prophet0 in forum Qt Quick
    Replies: 1
    Last Post: 30th May 2012, 19:23
  2. State Machine returning to previous state
    By akiross in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2011, 00:39
  3. Replies: 0
    Last Post: 19th December 2010, 16:03
  4. Replies: 0
    Last Post: 22nd February 2010, 09:30
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.