PDA

View Full Version : Selecting Items in QToolButton



Nfrancisj
12th April 2019, 20:49
13082
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

anda_skoa
13th April 2019, 09:19
I am not sure I understand.

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

Cheers,
_

Nfrancisj
17th April 2019, 07:03
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




def getActiveViewer():
for widget in QtGui.QApplication.allWidgets():
if widget.windowTitle() == nuke.activeViewer().node().name():
return widget
return False


def getViewerWidgets(qtObject, widgetTTSearch):
for c in qtObject.children():
found = getViewerWidgets(c)
if found:return found
try:
tt = c.toolTip().lower()
if tt.startswith(widgetTTSearch):
return c
except:
pass


widgetSearch = "view selection"
viewerWidgets = getViewerWidgets(getActiveViewer(), widgetSearch)
viewerWidgets.menu().actions()[1].trigger()

Nfrancisj
20th April 2019, 10:15
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!

anda_skoa
20th April 2019, 12:04
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 (https://www.kdab.com/development-resources/qt-tools/gammaray/).

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

ChrisW67
22nd April 2019, 03:25
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).

Nfrancisj
1st May 2019, 07:33
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. :)


i = toolButton.icon()
p = i.pixmap(i.availableSizes()[0])
e= p.toImage()
e.pixel(9,9)

Thanks again!