Qt学习(003-3)状态栏

在QT5.1下使用creator创建GUI项目mystatusbar。

建立文件mystatusbar.h:

#ifndef MYSTATUSBAR_H
#define MYSTATUSBAR_H

#include <QMainWindow>
#include <QStatusBar>
#include <QPushButton>
#include <QLabel>
#include <QString>
class MyStatusBar:public QMainWindow
{
    Q_OBJECT
public:
    MyStatusBar();

public slots:
    void buttonClick();

private:
    QPushButton *button;
    qint32 count;
};

#endif // MYSTATUSBAR_H



建立文件mystatusbar.cpp:

#include "mystatusbar.h"


MyStatusBar::MyStatusBar()
    :QMainWindow()
{
    this->count = 1;
    this->button = new QPushButton("Button",this);
    this->statusBar()->showMessage("ready");
    this->connect(this->button,SIGNAL(clicked()), this, SLOT(buttonClick()));
}

void MyStatusBar::buttonClick()
{
    this->statusBar()->showMessage(QString::number(this->count));
    this->count++;
}




修改main.cpp:

#include <QApplication>
#include "mystatusbar.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MyStatusBar w;
    w.show();

    return a.exec();
}



运行结果:

Qt学习(003-3)状态栏

你可能感兴趣的:(qt)