PDA

View Full Version : Independent Right-Click Menus



HiFly
19th February 2009, 19:36
Let me first say I've been using this forum passively for a while now and it has proved to be an invaluable resource in solving the majority of my PyQt questions. Now onto my main problem... I am currently developing an application that allows the user to distribute a frame sequence (3d rendering) across multiple computers for rendering. This application allows the user to not only view the current frames being rendered but also the connected hosts. Initially I was going to use a set of menus and buttons to control the tables then I realized it made more sense to create a right-click drop down menu. My main problem is that I cannot figure out a few things:

1.) ONLY popup the drop down menu IF it is over one of the table widgets (or perhaps more specifically, any row)
2.) Create individual menu sets for each table widget.
3.) Menu sets are based off of current information. For example, if the host is inactive you can only activate the host. (this is easy using if/else statements, I just need the get #1/2 working)

Other Items:
1.) If you don't know anything about PyQt please answer anyway as most of the information will carry over to Python.

2.) The gui was created using Qt Designer so all widgets are referenced using self.ui.<widget_name>

Thank you in advance for your help!

http://www.opalmer.com/pyfarm/download/other/pyfarm_tables_example.gif

wysota
19th February 2009, 19:47
Ok, but what exactly is the problem? What is that you don't know how to do?

HiFly
19th February 2009, 23:28
If I use contextMenuEvent to create the pop up menu the menu will appear where ever and when ever the right mouse button is clicked, even outside of the tables. What I want to be able to do is pop up the menu only if the mouse button was pressed over a table widget. Secondly, I would like to be able to create individual menus for each table widget.

Example 1: User click the right mouse button over the main window but not over one of the tables, nothing happens as a result.

Example 2: User clicks the right mouse button over the host table and a menu containing several actions specific to host management pops up under the mouse cursor.

aamer4yu
20th February 2009, 08:12
Where are you catching the contextmenu event and showing the context menu ?
You can always check if an item exists under the mouse pos and show menu only in that case :)

spirit
20th February 2009, 08:40
read this thread, it should help you QTreeWidget & context menu (http://www.qtcentre.org/forum/f-qt-programming-2/t-qtreewidgetitem-have-contextmenu--18929.html)

wysota
20th February 2009, 08:58
What I want to be able to do is pop up the menu only if the mouse button was pressed over a table widget.
So reimplement contextMenuEvent() for that widget.


Secondly, I would like to be able to create individual menus for each table widget.

Then do it, what is the problem? Subclass the table widget and reimplement its event handler or use a different QWidget::contextMenuPolicy to avoid subclassing tables.