繁体   English   中英

如何使用Qt中的代码将小部件添加到中央小部件中

[英]How to add a widget into central Widget using code in Qt

我需要使用代码向窗体添加小部件,但不必使用QHBoxLayout或QVBoxLayout。

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    fields[0] = new CustomLabel();
    fields[0]->setText("Hello");
    //how to show it  

}

您可以简单地使用setCentralWidget()

setCentralWidget()的文档

像这样的ui->setCentralWidget(fields[0]); 或者用this替换ui

但是,要显示许多小部件,您必须使用包含标签矩阵(小部件)的小部件。 当您具有包含矩阵的父窗口小部件时,使用setCentralWidget()对其进行显示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM