简体   繁体   中英

Qt : Qlabel and QPushButton in a QVBoxLayout

I have an issue, when I'm trying to add a QLabel and a QPushbutton object into a QVBoxLayout. The problem is, that it adds too much space between them like in the picture

样品

Here is a code example of creating the layouts and the labels, and adding them. I'm adding the buttons later on, but that is just with another ->addWidget(button).

jobbcimke= new QLabel(trUtf8("Jobb oldal"));
jobbkozepcimke= new QLabel(trUtf8("Jobb part"));
balcimke= new QLabel(trUtf8("Bal oldal"));
balkozepcimke=new QLabel(trUtf8("Bal part"));

jobbfelulet=new QVBoxLayout();
jobbkozepfelulet=new QVBoxLayout();
balkozepfelulet=new QVBoxLayout();
balfelulet=new QVBoxLayout();
osszefogo=new QHBoxLayout();

jobbfelulet->setAlignment(Qt::AlignRight);
jobbkozepfelulet->setAlignment(Qt::AlignRight);
balfelulet->setAlignment(Qt::AlignLeft);
balkozepfelulet->setAlignment(Qt::AlignLeft);

balfelulet->addWidget(balcimke);
balkozepfelulet->addWidget(balkozepcimke);
jobbfelulet->addWidget(jobbcimke);
jobbkozepfelulet->addWidget(jobbkozepcimke);

osszefogo->addLayout(balfelulet);
osszefogo->addLayout(balkozepfelulet);
osszefogo->addLayout(jobbkozepfelulet);
osszefogo->addLayout(jobbfelulet);

setLayout(osszefogo);

How could I remove the space between them, or is there a better method to do this? I've created the labels for the layout size allocation.

如果你挖掘到的文档有一个setSpacing(int x)的方法QLayouts ,使您可以在元素之间编辑间距,你可能还需要添加一些QSpacerItems来取得位置正是您想要的话,还是应用约束带setGeometry(QRect rect)方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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