Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context Menu Creation with ‪ Qt Designer(Qt Creator IDE)

How can i create a Context menu in Qt Designer (1.3)? Certainly I want to create it with out writing one line code!!

like image 578
Mohammad Sheykholeslam Avatar asked Apr 26 '10 05:04

Mohammad Sheykholeslam


People also ask

How do I create a menu bar in Qt?

To access this QMenuBar and populate it with things of your choice, just call menuBar() from your QMainWindow instance. To add a submenu to a QMenuBar , use QMenuBar::addMenu .

Is Qt Designer and Qt Creator the same?

Qt Creator is Qt's IDE. You don't have to use it, but it greatly simplifies Qt development. Qt Designer is a graphical tool that lets you build QWidget GUIs. Qt Quick Designer is similar, but for building QML GUIs.

How do I display context menu?

The context menu (right-hand mouse button or SHIFT+F10 ) allows you to display a context-sensitive menu. The context is defined by the position of the mouse pointer when the user requests the menu. A context menu allows the user to choose functions that are relevant to the current context.

Why Qt Designer is used?

Qt Designer provides a user-friendly graphical interface that allows you to quickly create GUIs. This can boost your productivity as a developer and shorten your development cycles. Hand coding your GUIs, on the other hand, can give you much more control over them.


1 Answers

You need two steps in Qt Designer and a few lines of code in the form constructor:

  • Set the contextMenuPolicy of your widget to the value ActionsContextMenu.

  • Create actions using the action editor tab.

  • For each action you created in Qt Designer, put a line such as the following in the form constructor: ui->yourwidget->addAction(ui->youraction);

like image 157
Jose F. Velez Avatar answered Sep 22 '22 10:09

Jose F. Velez