Results 1 to 7 of 7

Thread: Selecting Items in QToolButton

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

    Default Selecting Items in QToolButton

    toolButton.jpg
    I'm using PySide, and I was able to get the QToolButton object. It is a drop down menu with a few actions.
    What I am trying to do is:
    1) Get a list of items in the QToolButton and for now just print the names... "Camera1, Camera2 ..."
    2) Check an item other than the default.

    Any help would be greatly appreciated!

    Nick

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting Items in QToolButton

    I am not sure I understand.

    You created that list either in the widget designer or in code, no?

    Cheers,
    _

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

    Default Re: Selecting Items in QToolButton

    This is a software called Nuke. It was created by The Foundry using PySide. The developers left the PySide side open so Artist could write tools for Nuke.

    I was able to find the answer I was looking for in a different forum.
    I'll post it here if anyone comes searching in the future. The last line is what i was looking for.

    Thanks for checking in Anda


    Qt Code:
    1. def getActiveViewer():
    2. for widget in QtGui.QApplication.allWidgets():
    3. if widget.windowTitle() == nuke.activeViewer().node().name():
    4. return widget
    5. return False
    6.  
    7.  
    8. def getViewerWidgets(qtObject, widgetTTSearch):
    9. for c in qtObject.children():
    10. found = getViewerWidgets(c)
    11. if found:return found
    12. try:
    13. tt = c.toolTip().lower()
    14. if tt.startswith(widgetTTSearch):
    15. return c
    16. except:
    17. pass
    18.  
    19.  
    20. widgetSearch = "view selection"
    21. viewerWidgets = getViewerWidgets(getActiveViewer(), widgetSearch)
    22. viewerWidgets.menu().actions()[1].trigger()
    To copy to clipboard, switch view to plain text mode 
    Last edited by Nfrancisj; 17th April 2019 at 07:25.

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

    Default Re: Selecting Items in QToolButton

    Hey Anda, if you're still here, I have a second relating question.

    If you could, please take a look at the image I posted earlier. Notice the camera icon next to the word 'default'.
    That is a QToolbutton with 2 icons. When pressed/released it toggles the icon red/gray. (There is no 'down' state)
    I'm trying to find a way to identify the state of the QToolbutton. If it's gray, I want to .click() it to make it red. If it's red, then don't do anything. I looked through the API, and didn't find anything helpful. Thoughts on achieving this?
    What I'm trying now involves getting the QIcon, then the pixmap. I didn't find anything in the QIcon docs that would get/print the pixmap name/id.

    Would you happen to know how I would get the pixmap assigned to the 2 QIcons?

    Thanks for all your help!

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Selecting Items in QToolButton

    A pixmap doesn't have an "id", it is essentially just image data.

    What you can probably do is convert the pixmap into a QImage using the toImage() function and then access the pixel data to check the color.

    However, the program might have the state accessible in some way elsewhere, it needs to know that for its own processing.

    Cheers,
    _

    P.S.: since you are trying to interface with an application with unknown internals, I can highly recommend to look at GammaRay.

    It is a tool specifically designed to gain insight into the internals of Qt applications.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,555
    Thanks
    13
    Thanked 1,581 Times in 1,510 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Selecting Items in QToolButton

    Quote Originally Posted by Nfrancisj View Post
    What I'm trying now involves getting the QIcon, then the pixmap. I didn't find anything in the QIcon docs that would get/print the pixmap name/id.
    If the button toggles between grey and red on successive clicks then QAbstractButton::setCheckable() was set to true and QAbstractButton::checked() should give you what you want. Seems that since you are getting to the QIcon it should be easy to identify the QToolButton (i.e. QAbstractButton).

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

    Default Re: Selecting Items in QToolButton

    Quote Originally Posted by anda_skoa View Post

    What you can probably do is convert the pixmap into a QImage using the toImage() function and then access the pixel data to check the color.

    This worked well.

    Qt Code:
    1. i = toolButton.icon()
    2. p = i.pixmap(i.availableSizes()[0])
    3. e= p.toImage()
    4. e.pixel(9,9)
    To copy to clipboard, switch view to plain text mode 

    Thanks again!

Similar Threads

  1. Selecting items in a QTreeWidget with the keyboard
    By Berryblue031 in forum Qt Programming
    Replies: 2
    Last Post: 19th June 2013, 11:12
  2. Replies: 1
    Last Post: 22nd October 2012, 11:02
  3. QTableView problem - selecting multiple items
    By junhonguk in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2012, 15:16
  4. Replies: 1
    Last Post: 12th November 2009, 19:05
  5. Replies: 1
    Last Post: 7th April 2006, 12:13

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.