当前位置: 代码迷 >> QT开发 >> QT中想在mainwindow里平添widget的函数
  详细解决方案

QT中想在mainwindow里平添widget的函数

热度:24   发布时间:2016-04-25 03:26:14.0
QT中想在mainwindow里添加widget的函数
我在mainwindow中想添加几个widget函数,例如:
void widget::showEvent(QShowEvent *)
{
    QMessageBox::information(
            this,
            "Information",
            "showEvent!",
            QMessageBox::Ok);
}
虽然编译通过但貌似没有调用这个函数。
求各位大神指导一下在mainwindow中怎样添加widget函数或控件?
------解决方案--------------------
引用:
我在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);
}


  相关解决方案