我需要什么才能在QWidget
派生类中调用showEvent()
?如何让showEvent()被调用?
ConfigMenuForm.h
//simplified the code of the class declaration
class ConfigMenuForm : public QWidget
{
Q_OBJECT
public:
explicit ConfigMenuForm(QWidget *parent = 0);
~ConfigMenuForm();
signals:
public slots:
private slots:
protected:
void showEvent(QShowEvent *event) override; //with or without the override keyword, no change
private:
}
ConfigMenuForm.cpp
//amongst others
void ConfigMenuForm::showEvent(QShowEvent * event)
{
//do some stuff here - really simple
}
我不能拥有它触发时我show()
我的小工具...... 我指的是代码有没有效果和放置中断点时,它不会停止,所以我假设该事件未被触发。
我在做什么错?
编辑 - 加入更多的代码和精度:
我使用QtCreator 3.0.0使用Qt 5.2.0(2010 MSVC,32位)
//creating the widget in the main window's constructor (class Viewer)
// ConfigMenuForm calls hide() in its own constructor
m_configMenuForm = new ConfigMenuForm(this);
然后当我按下一个按钮主窗口
void Viewer::ontBConfigClicked()
{
m_configMenuForm->show();
}
什么让我困惑的是,m_configMenuForm
实际上是在主窗口的顶部显示,它变得可见,正确的工作!只是showEvent没有被调用。
你是怎么调用这个小部件的'show'的? –
为了让'showEvent'打电话,你只需要做你*说过的*你已经完成的事情。这是一个[最小示例](http://pastebin.com/3FCjuS990)。如果您正在通过放置一个断点进行测试,也许您没有将调试器附加到您的应用程序中。如果您使用的是Qt Creator,则需要使用“开始调试”按钮“F5”(而不是“运行”按钮“ctrl + R”)。 – Mike
@Jonathan Mee:直接调用拥有这个小部件的另一个小部件的show()插槽 – RDK