Search code examples
c++qtuser-interfaceqwidget

QWidget over another widget


I have graphs (QCustomPlot) that are arranged vertically with a separator (QSplitter).

How can I get the window as in the picture when I click on the right button? I know how to handle the right button signal, but I can not understand how to display the window I need.

enter image description here


Solution

  • Add a QMenu as a member of your widget. In .h:

    #include <QMenu>
    #include <QAction>
    .....
    QMenu menu;
    

    In constructor:

    QAction* action=new QAction("save",this);
    connect(action,SIGNAL(triggered()),this,SLOT(save()));
    menu.addAction(action);
    QAction* action2=new QAction("clear",this);
    connect(action2,SIGNAL(triggered()),this,SLOT(clear()));
    menu.addAction(action2);
    setContextMenu(&menu);