qt mainwindows上添加布局

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
 
    //qhboxLayout1部分代码
    QLabel* monitorLabel= new QLabel("监听端口");
    m_monitorSpinBox = new QSpinBox();
    m_monitorSpinBox->setRange(0,65535);
    m_startButton = new QPushButton("启动服务");
    m_stopButton = new QPushButton("停止服务");
    m_stopButton->setEnabled(false);
    QHBoxLayout *qhboxLayout1 = new QHBoxLayout;
    qhboxLayout1->addWidget(monitorLabel);
    qhboxLayout1->addWidget(m_monitorSpinBox);
    qhboxLayout1->addWidget(m_startButton);
    qhboxLayout1->addWidget(m_stopButton);
 
    //qhboxLayout2部分代码
    QLabel* sendLabel=new QLabel("发送消息");
    QHBoxLayout *qhboxLayout2 = new QHBoxLayout;
    qhboxLayout2->addWidget(sendLabel);
 
    //qhboxLayout3部分代码
    m_sendTextedit = new QTextEdit;
    m_sendTextedit->setEnabled(false);
    m_sendTextedit->setFixedHeight(50);
    m_sendButton= new QPushButton("发送");
    m_sendButton->setEnabled(false);
    m_sendButton->setFixedHeight(50);
 
    QHBoxLayout *qhboxlayout3 = new QHBoxLayout;
    qhboxlayout3->addWidget(m_sendTextedit,2);
    qhboxlayout3->addWidget(m_sendButton,1);
 
    //qvboxlayout411
    QLabel* receiveLabel = new QLabel("接收消息");
    m_receiveTextEdit = new QTextEdit();
    m_receiveTextEdit->setReadOnly(true);
 
    QVBoxLayout *qvboxlayout411 = new QVBoxLayout;
    qvboxlayout411->addWidget(receiveLabel);
    qvboxlayout411->addWidget(m_receiveTextEdit);
 
    //qhboxlayout412
    m_cleanButton = new QPushButton("清除");
    m_cleanButton->setEnabled(false);
    QHBoxLayout *qhboxlayout412 = new QHBoxLayout;
    qhboxlayout412->addStretch();
    qhboxlayout412->addWidget(m_cleanButton);
 
    //qvboxlayout41
    QVBoxLayout *qvboxlayout41 = new QVBoxLayout;
    qvboxlayout41->addLayout(qvboxlayout411);
    qvboxlayout41->addLayout(qhboxlayout412);
 
    //qvboxlayout42
    QLabel* linkclientLabel=new QLabel("连接客户端");
    m_linkclientListWidget=new QListWidget;
    QVBoxLayout* qvboxlayout42 = new QVBoxLayout;
    qvboxlayout42->addWidget(linkclientLabel);
    qvboxlayout42->addWidget(m_linkclientListWidget);
 
    //qvboxlayout4
    QHBoxLayout *qhboxlayout4 = new QHBoxLayout;
    qhboxlayout4->addLayout(qvboxlayout41,2);
    qhboxlayout4->addLayout(qvboxlayout42,1);
 
    //mainlayout
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(qhboxLayout1,1);
    mainLayout->addLayout(qhboxLayout2,0.5);
    mainLayout->addLayout(qhboxlayout3,1);
    mainLayout->addLayout(qhboxlayout4,3);
 
    //this->setLayout(mainLayout);
     this->setWindowTitle("Websocket Server");
     ui->setupUi(this);
     ui->centralWidget->setLayout(mainLayout);

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值