Qt学习笔记之QPushButton 按钮类
程序员文章站
2022-05-28 12:10:17
...
- 在窗体中创建按钮 A,点击按钮 A,改变文字为按钮 B。实例代码如下
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QPushButton *pbt;
private slots:
void textButton();
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.H"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
pbt=new QPushButton("bt a",this);
pbt->setGeometry(QRect(50,50,120,120));
connect(pbt,SIGNAL(released()),this,SLOT(textButton()));
}
void MainWindow::textButton()
{
pbt->setText("bt b");
}
MainWindow::~MainWindow()
{
delete ui;
}
main.cpp
#include "mainwindow.H"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
下一篇: Python多元线性回归