Results 1 to 6 of 6

Thread: Does QToolButton have a RELEASED Signal ?

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    82
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Does QToolButton have a RELEASED Signal ?

    Does QToolButton have a 'RELEASED' signal?

    I see these two, but no release.
    Qt Code:
    1. self.snapshotBtn.pressed.connect(self.printMe)
    2. self.snapshotBtn.triggered.connect(self.printMe)
    To copy to clipboard, switch view to plain text mode 

    What I am trying to do is fire a signal when the user releases the QToolButton.

    Ideas?

    Please and Thanks,

    Nick

    My Test Code
    Qt Code:
    1. import sys
    2. try:
    3. from PySide import QtCore, QtGui, QtGui as QtWidgets
    4. except:
    5. from PySide2 import QtCore, QtGui, QtWidgets
    6.  
    7.  
    8. class Example(QtWidgets.QWidget):
    9. def __init__(self):
    10. super(Example, self).__init__()
    11.  
    12. self.initUI()
    13.  
    14. def printMe(self):
    15. print("thisWorks")
    16.  
    17. def initUI(self):
    18.  
    19. self.snapshotBtn = QtWidgets.QToolButton(self)
    20. self.snapshotMenu = QtWidgets.QMenu()
    21. self.captureAction = QtWidgets.QAction("")
    22. #self.viewAction = QtWidgets.QAction("")
    23.  
    24. self.snapshotBtn.setObjectName("SnapShotButton")
    25. #self.snapshotBtn.setIcon(QtGui.QIcon("C:/Users/nfran/.nuke/icons/cameraIcon.png"))
    26. #self.viewAction.setIcon(QtGui.QIcon("C:/Users/nfran/.nuke/icons/cameraIcon.png"))
    27. self.captureAction.setIcon(QtGui.QIcon("C:/Users/nfran/.nuke/icons/cameraIcon.png"))
    28.  
    29.  
    30. self.snapshotMenu.addAction(self.captureAction)
    31. #self.snapshotMenu.addAction(self.viewAction)
    32.  
    33. self.snapshotBtn.setMenu(self.snapshotMenu)
    34. self.snapshotBtn.move(50, 50)
    35. self.snapshotMenu.setStyleSheet("""QMenu{ width: 30px; }""")
    36. self.snapshotBtn.setStyleSheet("""#SnapShotButton {image: url(C:/Users/nfran/.nuke/icons/cameraIcon.png);} #SnapShotButton:hover {image: url(C:/Users/nfran/.nuke/icons/cameraIcon_Hover.png);}""")
    37.  
    38. self.snapshotBtn.pressed.connect(self.printMe)
    39. self.snapshotBtn.triggered.connect(self.printMe)
    40.  
    41. self.setGeometry(300, 300, 250, 150)
    42. self.setWindowTitle('Tooltips')
    43. self.show()
    44.  
    45.  
    46.  
    47. def main():
    48. app = QtWidgets.QApplication(sys.argv)
    49. ex = Example()
    50. sys.exit(app.exec_())
    51.  
    52.  
    53. if __name__ == '__main__':
    54. main()
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    443
    Thanked 60 Times in 56 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does QToolButton have a RELEASED Signal ?


  3. The following user says thank you to ChristianEhrlicher for this useful post:

    Nfrancisj (29th June 2019)

  4. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    82
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Does QToolButton have a RELEASED Signal ?

    hmm... I did see the docs.
    So, I guess I'm using the wrong Signal. The behavior I'm trying to get is more of a pressed and hold down kinda thing. I'm making a before and after dialog window. Where I have 2 images, and when I push the button and hold it down, it shows the image before it was color-corrected, and when I let the button go, it returns to the color-corrected image. Pressed does switch to the unmodified image, but the Release doesn't switch back. Though, when I quickly click and release, it fires both.

    How would I go about implementing a Press and Hold, and Release? Is the QToolButton the right widget for this?

    Thanks,

    Nick

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,072
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Does QToolButton have a RELEASED Signal ?

    Pressed does switch to the unmodified image, but the Release doesn't switch back.
    That's two unrelated things. If your slots for handling pressed() and released() are being called at the right times, then the problem is in your code for restoring the image in the slot that handles released(). If you are connecting both signals to the same slot, then you probably have an error in your logic for keeping track of which image should be displayed.

    Note that if you move the cursor off the tool button before you release the mouse, you will never get a released() signal for that button. So it would then be possible for your image to get stuck in the unmodified state. This is why the clicked() signal works as it does - you will get a clicked() signal only if the mouse is pressed and then released while on the button. You won't get a clicked() if either the press or release occur when the cursor is not on the button. It's this behavior that allows a user to "cancel" a click by simply moving off the button before releasing.

    You might get more predictable behavior if you use a checkable button. (QAbstractButton::setCheckable()) This would give you a two state button - click once and it goes to the checked state, click again and it goes back to unchecked. You would connect to the QAbstractButton::toggled() signal and examine the state of the "checked" parameter of the signal to determine which image to display.

    Using a checkable button would also give you the flexibility to implement other features - like being able to zoom in on the image or pan it around. You can't do that it you are requiring the user to keep the mouse pressed and on the button all the time.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    Nfrancisj (29th June 2019)

  7. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    82
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Does QToolButton have a RELEASED Signal ?

    I was able to get the behavior I was looking for by using the QPushButton instead of the QToolButton.
    Thank you very much for all the information.

  8. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,072
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Does QToolButton have a RELEASED Signal ?

    I was able to get the behavior I was looking for by using the QPushButton instead of the QToolButton.
    That's very hard to believe. The clicked(), released(), pressed(), and toggled() signals for QPushButton and QToolButton are all implemented by the base class QAbstractButton, so there is no difference in behavior between the two derived classes when it comes to those signals. QToolButton adds one more signal, triggered(), which is emitted when the QAction associated with the button is executed (i.e. the tool button is clicked), but you aren't using that feature in your code.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QToolButton Leave Event on Mouse Leave QToolButton
    By neohaider in forum Qt Programming
    Replies: 6
    Last Post: 29th April 2019, 05:04
  2. QToolButton outside of QToolBar
    By dictoon in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2016, 22:15
  3. Can't See QToolButton pressed Signal from QTableWidget
    By mbrusati in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2008, 20:06
  4. Need help with QToolButton
    By philipp1 in forum Qt Programming
    Replies: 12
    Last Post: 27th October 2006, 15:37
  5. Need help with QToolButton
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2006, 14:55

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.