環境:QT5.5
画面を右と左にわけて、画面左側に縦並びに3つのボタンを配置する。
Qt Creatorで画面を作ったほうが楽なのですが、ウィジェットの配置が固定になってしまい、画面の拡大・縮小時にレイアウトが固定されてしまうため、プログラム側で作成。
リンク
https://doc.qt.io/qt-5/search-results.html?q=QWidget
https://doc.qt.io/qt-5/search-results.html?q=QMainWindow
https://doc.qt.io/qt-5/search-results.html?q=QCommandLinkButton
https://doc.qt.io/qt-5/search-results.html?q=QHBoxLayout
https://doc.qt.io/qt-5/search-results.html?q=QVBoxLayout
インクルードファイル
#include
#include
#include
#include
#include
Header File
private:
Ui::ClassA *ui;
// Window Object
QHBoxLayout *mainLayout;
QVBoxLayout *leftLayout;
QVBoxLayout *rightLayaut;
QCommandLinkButton *Button1;
QCommandLinkButton *Button2;
QCommandLinkButton *Button3;
//===========================================================
// コンストラクタ
//===========================================================
ClassA::ClassA(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ClassA)
{
ui->setupUi(this);
//*** 画面左側
// パーツ作成
mainLayout = new QHBoxLayout;
leftLayout = new QVBoxLayout;
button1 = new QCommandLinkButton(tr("ボタン1"));
button2 = new QCommandLinkButton(tr("ボタン2"));
button3 = new QCommandLinkButton(tr("ボタン3"));
// 配置
leftLayout->addWidget(button1);
leftLayout->addWidget(button2);
leftLayout->addWidget(button3);
leftLayout->addStretch();
//*** 画面右側
rightLayaut = new QVBoxLayout;
//*** 画面全体
mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayaut);
ui->centralwidget->setLayout(mainLayout);
コメント