鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 编程语言开发 > c++ > >

qt界面布局练习

来源:互联网 作者:佚名 时间:2016-06-16 09:04
qt5布局练习 Qt #include QApplication#include "qtestdialog.h" TestDialog::TestDialog(QWidget *parent) : QDialog(parent){ pushButton_1 = new QPushButton(tr("字体")); pushButton_2 = new QPushButton(tr("大小")); pushButton_3 = new QPushButton(t
qt5 布局练习 Qt
#include <QApplication>
#include "qtestdialog.h"
 
TestDialog::TestDialog(QWidget *parent)
    : QDialog(parent)
{
    pushButton_1 = new QPushButton(tr("字体"));
    pushButton_2 = new QPushButton(tr("大小"));
    pushButton_3 = new QPushButton(tr("消息记录"));
 
    QHBoxLayout* toolLayout = new QHBoxLayout;
    toolLayout->addWidget(pushButton_1);
    toolLayout->addWidget(pushButton_2);
    toolLayout->addStretch();
    toolLayout->addWidget(pushButton_3);
 
 
    pushButton_4 = new QPushButton(tr("关闭"));
    pushButton_5 = new QPushButton(tr("发送"));
    QHBoxLayout* buttomLayout = new QHBoxLayout;
    buttomLayout->addStretch();
    buttomLayout->addWidget(pushButton_4);
    buttomLayout->addWidget(pushButton_5);
 
 
    textEdit_1 = new QTextEdit;
    textEdit_2 = new QTextEdit;
    textEdit_2->setMaximumHeight(90);
    QVBoxLayout* leftlayout = new QVBoxLayout;
    leftlayout->addWidget(textEdit_1);
    leftlayout->addLayout(toolLayout);
    leftlayout->addWidget(textEdit_2);
    leftlayout->addLayout(buttomLayout);
 
 
 
    textEdit_3 = new QTextEdit;
    textEdit_3->setMaximumWidth(100);
    QVBoxLayout* rightlayout = new QVBoxLayout;
    rightlayout->addWidget(textEdit_3);
 
    QHBoxLayout* toplayout = new QHBoxLayout;
    toplayout->addLayout(leftlayout);
    toplayout->addLayout(rightlayout);
 
 
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(toplayout);
    setLayout(mainLayout);
 
 
}
#ifndef QTESTDIALOG_H
#define QTESTDIALOG_H
 
#include <QDialog>
#include <QTextEdit>
#include <QPushButton>
#include <QLayout>
 
class TestDialog:public QDialog
{
    Q_OBJECT
public:
    TestDialog(QWidget *parent = 0);
private:
    QTextEdit* textEdit_1;
    QTextEdit* textEdit_2;
    QTextEdit* textEdit_3;
    QPushButton* pushButton_1;
    QPushButton* pushButton_2;
    QPushButton* pushButton_3;
    QPushButton* pushButton_4;
    QPushButton* pushButton_5;
};
#include <QApplication>
#include "QTestDialog.h"
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    TestDialog* tdialog = new TestDialog;
    tdialog->show();
    return a.exec();
}
网友评论
<