![](/img/trans.png)
[英]Qt - Why can't I trigger mousePressEvent for my custom button in MainWindow
[英]Can't see my label and layout in MainWindow
delete layout();
QGridLayout *gridLayout = new QGridLayout(this);
int cont = 0;
for (Category c : categories) {
cont++;
QVBoxLayout *verticalLayout;
verticalLayout = new QVBoxLayout();
gridLayout->setSpacing(cont);
gridLayout->addLayout(verticalLayout, 0, cont - 1);
QLabel *l;
l = new QLabel();
l->setText(c.getName());
l->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(l);
}
在mainWindow
,我想補充一個gridLayout
和verticalLayout
使用時的標簽for
我的周期categories
您沒有將布局設置為任何小部件。 您必須為要應用它的小部件調用函數setLayout(gridLayout) 。 希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.