gpt4 book ai didi

qt - 如何在可折叠面板中实现大小相等的 FormLayout?

转载 作者:行者123 更新时间:2023-12-02 05:35:42 27 4
gpt4 key购买 nike

我认为这可能是两个独立的问题。在Qt4.8中,QFormLayout

The QFormLayout class manages forms of input widgets and their associated labels.

QFormLayout is a convenience layout class that lays out its children in a two-column form. The left column consists of labels and the right column consists of "field" widgets (line editors, spin boxes, etc.).

以下图为指导,

1)如何创建两个可折叠的可折叠面板?就像两个蓝色矩形一样?我已经尝试过QGroupBox,但其中没有任何可折叠属性。

2)如何使两个独立的QFormLayout具有相同的标签和字段比例,即使它们属于不同的可折叠面板?如附图所示,我们可以看出这两个表单布局已对齐,如绿线所示。

enter image description here

最佳答案

我希望您有可折叠的代码,并且只需要 QFormLayout 的代码。我相信这应该可以解决问题。

头文件:

#pragma once

#include <QtGui>
#include <QtCore>

class newQtApp : public QMainWindow {
Q_OBJECT

public :
newQtApp();
};

来源

newQtApp::newQtApp() : QMainWindow() {

cout << "Im being initialized...." << endl;
cout << "Setting window properties..." << endl;

QFormLayout *fLyt1 = new QFormLayout();
fLyt1->setLabelAlignment( Qt::AlignRight );
for( int i = 0; i < 5; i++ ) {
QLabel *lbl = new QLabel( QString( "Lyt 1, Label %1:" ).arg( i + 1), this );
lbl->setFixedWidth( 150 );
lbl->setAlignment( Qt::AlignRight );

fLyt1->addRow( lbl, new QLineEdit() );
}

QGroupBox *w1 = new QGroupBox( "First Collapsible", this );
w1->setLayout( fLyt1 );

QFormLayout *fLyt2 = new QFormLayout();
fLyt2->setLabelAlignment( Qt::AlignRight );
for( int i = 0; i < 5; i++ ) {
QLabel *lbl = new QLabel( QString( "Second Layout, Label %1:" ).arg( i + 1), this );
lbl->setFixedWidth( 150 );
lbl->setAlignment( Qt::AlignRight );

fLyt2->addRow( lbl, new QCheckBox( "Check this out!!" ) );
}

QGroupBox *w2 = new QGroupBox( "Second Collapsible", this );
w2->setLayout( fLyt2 );

QVBoxLayout *baseLyt = new QVBoxLayout();
baseLyt->addWidget( w1 );
baseLyt->addWidget( w2 );

QWidget *base = new QWidget( this );
base->setLayout( baseLyt );

setCentralWidget( base );
};

这是屏幕截图: enter image description here

关于qt - 如何在可折叠面板中实现大小相等的 FormLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20263846/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com