The action works well, but the action can not use from the setStatusTip()
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.
Code:
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
{public:
widget();
void createmenu();
void createaction();
private:
};
#endif // WIDGET_H
Code:
#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");
}
Code:
#include "widget.h"
#include <QtWidgets>
int main(int argv,char*argc[])
{
widget window;
window.show();
return app.exec();
}
Re: The action works well, but the action can not use from the setStatusTip()
What have you tried so far?
Cheers,
_
Re: The action works well, but the action can not use from the setStatusTip()
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.
Re: The action works well, but the action can not use from the setStatusTip()
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).
Re: The action works well, but the action can not use from the setStatusTip()
Quote:
Originally Posted by
rezas1000
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?
Re: The action works well, but the action can not use from the setStatusTip()
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).
Re: The action works well, but the action can not use from the setStatusTip()
Quote:
Originally Posted by
rezas1000
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,
_
Re: The action works well, but the action can not use from the setStatusTip()
Quote:
I see no code that indicates that.
Did you forget to post the code that sets up the status bar?
thank you very much
Quote:
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
Quote:
Can you see a status bar in your window at all?
thank you very much
Quote:
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():
Code:
#include <QtWidgets>
#include "widget.h"
widget::widget()
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->setStatusTip("Open a new file");
}
void widget::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}