Qt 對話方塊新增工具欄

林興南發表於2020-10-14
#ifndef DIALOGSIEMENSSETPARAMETER_H
#define DIALOGSIEMENSSETPARAMETER_H

#include <QDialog>
#include <QToolBar>
#include <QLabel>
#include <QGridLayout>
#include <QAction>
#include <QHBoxLayout>
namespace Ui {
class DialogSiemensSetParameter;
}

class DialogSiemensSetParameter : public QDialog
{
    Q_OBJECT

public:
    explicit DialogSiemensSetParameter(QWidget *parent = nullptr);
    ~DialogSiemensSetParameter();

private:
    Ui::DialogSiemensSetParameter *ui;


    QGridLayout gLay;
    QWidget widTool;
    QToolBar toolBar;
    QLabel testLab;
    QAction actTs;

    QHBoxLayout hBox;

};

#endif // DIALOGSIEMENSSETPARAMETER_H
#include "dialogsiemenssetparameter.h"
#include "ui_dialogsiemenssetparameter.h"

DialogSiemensSetParameter::DialogSiemensSetParameter(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogSiemensSetParameter)
{
    ui->setupUi(this);
    widTool.setGeometry(0,0,400,24);
    QHBoxLayout *  searchLayout  =   new  QHBoxLayout(&widTool);
    searchLayout->addWidget(&toolBar);

    testLab.setText("test");
    actTs.setText("acttest");
    toolBar.addWidget(&testLab);
    toolBar.addAction(&actTs);

    gLay.setMenuBar(&widTool);

    hBox.addWidget(ui->listWidget);
    hBox.addWidget(ui->stackedWidget);
    gLay.addLayout(&hBox,1,1);
    setLayout(&gLay);

}

DialogSiemensSetParameter::~DialogSiemensSetParameter()
{
    delete ui;
}

在這裡插入圖片描述

相關文章