Important: Please read the Qt Code of Conduct -

Regarding context menu

  • Hi All

    I have created a Qwidget window on which i have place QTreeWidget.
    Then i have created a context menu,& on right click of mouse i tried to show this context menu.
    But I am not able to connect my signal to the slot.

    connect(treewidgetptr,SIGNAL(customContextMenuRequested ( const QPoint & pos ) ),this,SLOT(contextMenuEvent(QContextMenuEvent * event )));@

  • The signal and the slot must have the same arguments, here you have QPoint and QContextMenuEvent types.

    From the doc: "The signals and slots mechanism is type safe: The signature of a signal must match the signature of the receiving slot."

  • In addition, you should not pass any parameter names, just types.

  • If your context menu is based on QAction, you just can set the contextMenuPolicy to Qt::ActionsContextMenu.

    Then, all you need to do is insering your actions with "QWidget::addAction":

Log in to reply