在Qt5.3.1中如何用addwidget对控件进行布局?

在Qt5.3.1中如何用addwidget对控件进行布局?,第1张

完全没问题啊,我的Qt也是5.3.1,下面代码是在QDialog的构造函数中的,后面的和你的代码完全一样:

    

    QLabel *label1 = new 首仔QLabel

 宽芹仿   label1->setText("label1")

    QLineEdit *lineEdit = new QLineEdit

    QLabel *label2 = new QLabel

    label2->setText("label2")

    QPushButton *button = new QPushButton

    button->setText("button")

    QGridLayout *mainLayout = new QGridLayout(this)

    mainLayout->addWidget(label1,0,0)

    mainLayout->addWidget(lineEdit,0,1)

    mainLayout->addWidget(label2,1,0)

    mainLayout->addWidget(button,1,1)

这是运慎纤行截图:

可以采枣含用布局,然后用addStretch()

举例:

#include<QApplication>

#include<QWidget>

#include<QHBoxLayout>

#include<QPushButton>

int main(int argc,char* argv[])

{

QApplication app(argc,argv)

QWidget *w=new QWidget

QHBoxLayout *l=new QHBoxLayout(w)

QPushButton *b=new QPushButton(QObject::tr("Close"))

geometry它处于凳态笑右边,如果要右下角,可以类似的布闭伏局


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11986977.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存