View Full Version : The action works well, but the action can not use from the setStatusTip()
rezas1000
19th September 2014, 11:32
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>
class widget:public QMainWindow
{public:
widget();
void createmenu();
void createaction();
private:
QTextEdit*text;
QMenu*filemenu;
QAction*newact;
};
#endif // WIDGET_H
#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");
}
#include "widget.h"
#include <QtWidgets>
int main(int argv,char*argc[])
{
QApplication app(argv,argc);
widget window;
window.show();
return app.exec();
}
anda_skoa
19th September 2014, 13:26
What have you tried so far?
Cheers,
_
rezas1000
19th September 2014, 19:17
I try to display the message on the status bar, when the mouse goes on the new action.But in this code, it does not work.
d_stranz
20th September 2014, 01:37
What happen when you derive a class from QMainWindow, but forget to include the Q_OBJECT macro in the class definition? (Look at the header file for any class derived from a Qt QObject class and compare that with the definition of your "widget" class in your header file).
wysota
20th September 2014, 08:03
I try to display the message on the status bar, when the mouse goes on the new action.But in this code, it does not work.
Can you see a status bar in your window at all?
ChrisW67
20th September 2014, 08:13
The code as posted does not display a status bar. When you create the status bar it shows the specified text just fine (Linux, Qt 5.3).
anda_skoa
20th September 2014, 10:33
I try to display the message on the status bar, when the mouse goes on the new action.
I see no code that indicates that.
Did you forget to post the code that sets up the status bar?
Cheers,
_
rezas1000
20th September 2014, 12:03
I see no code that indicates that.
Did you forget to post the code that sets up the status bar?
thank you very much
The code as posted does not display a status bar. When you create the status bar it shows the specified text just fine (Linux, Qt 5.3).
thank you very much
Can you see a status bar in your window at all?
thank you very much
What happen when you derive a class from QMainWindow, but forget to include the Q_OBJECT macro in the class definition? (Look at the header file for any class derived from a Qt QObject class and compare that with the definition of your "widget" class in your header file).
thank you very much
the code is working well, Because I changed the code and I added the createStatusBar():
#include <QtWidgets>
#include "widget.h"
widget::widget()
{text=new QTextEdit;
resize(250,250);
setCentralWidget(text);
createaction();
createmenu();
createStatusBar();
}
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");
}
void widget::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.