Hello, I want to build one menu and one action with QContextMenuEvent,but this code doesn't build.please help me.thank you.
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
{public:
widget();
void createmenu
(QMenu*filemenu
);
void createaction();
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
class widget:public QMainWindow
{public:
widget();
void event(QContextMenuEvent*e);
void createmenu(QMenu*filemenu);
void createaction();
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
#include <QContextMenuEvent>
#include <QtWidgets>
#include "widget.h"
widget::widget()
{
resize(250,250);
}
{Q_UNUSED(e);
createmenu(&filemenu);
}
void widget
:: createmenu(QMenu*file) {
file =menuBar()->addMenu("File");
createaction();
}
void widget:: createaction()
{
newact.setShortcut(key);
}
#include <QContextMenuEvent>
#include <QtWidgets>
#include "widget.h"
widget::widget()
{
resize(250,250);
}
void widget::event(QContextMenuEvent*e)
{Q_UNUSED(e);
QMenu filemenu(this);
createmenu(&filemenu);
}
void widget:: createmenu(QMenu*file)
{
file =menuBar()->addMenu("File");
createaction();
}
void widget:: createaction()
{
QAction newact("Open",this);
QKeySequence key(tr("Ctrl+O"));
newact.setShortcut(key);
}
To copy to clipboard, switch view to plain text mode
#include "widget.h"
#include <QtWidgets>
int main(int argv,char*argc[])
{
widget window;
window.show();
return app.exec();
}
#include "widget.h"
#include <QtWidgets>
int main(int argv,char*argc[])
{
QApplication app(argv,argc);
widget window;
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks