我在mainwindow中想添加几个widget函数,例如:
void widget::showEvent(QShowEvent *)
{
QMessageBox::information(
this,
"Information",
"showEvent!",
QMessageBox::Ok);
}
虽然编译通过但貌似没有调用这个函数。
求各位大神指导一下在mainwindow中怎样添加widget函数或控件?
------解决方案--------------------
我刚才貌似看错问题了,我试了试没问题啊
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
protected:
virtual void showEvent(QShowEvent *);
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::showEvent(QShowEvent *)
{
QMessageBox::information(this,tr("info"),tr("alert"),Qt::NoButton);
}