Hello.in this code, the QMenu and the QAction work well.but the newact can not use from the setStatusTip("Open a new file"); thank you.
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
{public:
widget();
void createmenu();
void createaction();
private:
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
class widget:public QMainWindow
{public:
widget();
void createmenu();
void createaction();
private:
QTextEdit*text;
QMenu*filemenu;
QAction*newact;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
#include <QtWidgets>
#include "widget.h"
widget::widget()
resize(250,250);
setCentralWidget(text);
createaction();
createmenu();
}
void widget::createmenu()
{filemenu=menuBar()->addMenu(tr("File"));
filemenu->addAction(newact);
}
void widget::createaction()
{
newact
=new QAction(tr
("&New"),
this);
newact->setStatusTip("Open a new file");
}
#include <QtWidgets>
#include "widget.h"
widget::widget()
{text=new QTextEdit;
resize(250,250);
setCentralWidget(text);
createaction();
createmenu();
}
void widget::createmenu()
{filemenu=menuBar()->addMenu(tr("File"));
filemenu->addAction(newact);
}
void widget::createaction()
{
newact=new QAction(tr("&New"),this);
newact->setShortcut(QKeySequence::New);
newact->setStatusTip("Open a new file");
}
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