PDA

View Full Version : QToolButton How to close/dismiss the menu?



Nfrancisj
15th May 2019, 20:15
I'm having some trouble dismissing the QToolBar DropDown Menu.

I uploaded a little gif to help explain.
https://ibb.co/8X8VCS5

I have 2 QToolButtons. One has a dope down menu, the other is just a clicker.
The pulldown, when clicked on, will search for any Cameras and populate them in the menu. If it isn't clicked on, it doesn't update the menu. It just has 'default'.
The other Qtoolbutton is the little camera icon next to it. In the attached gif link, it's the button that turns red. This button will only activate if a camera is selected from the pull-down. So i need to trigger the menu, and have it load all the cameras, then select a camera, then push the camera icon.

What it's doing:

I am programmatically clicking/activating these two buttons with a third button called 'Active Viewer Setup.'
using the code below, i open the menu, forcing it to populate. (Camera01 gets added)

cameraSelectionButton.showMenu()

Then I select Camera01 from the menu if it matches my text.

[camera.trigger() for camera in cameraSelectionButton.menu().actions() if camera.text() == 'Camera01']

Then the Camera Icon button gets clicked to activate. (turns red)

cameraActivateButton.click()

The Problem:

The Menu doesn't close/dismiss. If you take a look at the gif, You'll see everything gets clicked, and activates, but it doesn't show because the menu is still open. I have to do a second click, which closes the menu and then things update. When I omit the code for showMenu, and click it myself using the mouse, everything works. This is how I know its the menu not closing that is causing the issue.

Is there a way to close this menu ? Any advice/alternative ways of doing this?

Thanks!

Nick

anda_skoa
17th May 2019, 14:37
It is probably enough to just call "close()" on the menu.

Cheers,
_

Nfrancisj
17th May 2019, 18:43
Thanks for your reply.

I tried close() earlier while looking for a solution. Unfortunately, it seems like the button, in it's open state won't allow anything else to update. (graphics wise).
Is there a way to find the 'Slot', or trigger the 'Signal' that it sends without opening the menu? It sends a "fetch all cameras in scene" , but I don't know the name.

Thanks,

Nick