【发布时间】:2017-09-13 09:28:57
【问题描述】:
这有点令人沮丧,但我找不到设置 QPushButton 大小的正确方法。根据我的阅读,我认为这段代码应该可以工作:
// SEND BUTTON
sendButton = new QPushButton(this);
sendButton->setText("Send");
sendButton->setMinimumSize(QSize(0,0));
sendButton->setMaximumSize(QSize(10000,10000));
sendButton->setGeometry(QRect(QPoint(30, 100),QSize(10, 20)));
connect(sendButton, &QPushButton::released, this, &MainWindow::handleSendButton);
// CENTRAL WIDGET
QWidget* centralWidget = new QWidget(this);
centralWidget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
// LAYOUT
QGridLayout* layout = new QGridLayout(centralWidget);
layout->addWidget(sendButton,0,0,0,0);
但按钮总是扩展到整个应用程序窗口。你能帮忙吗?
【问题讨论】:
-
你确实将它的最大尺寸设置得相当大(减少这个)。它将在网格布局中最大化,因为它没有 Spacers 作为邻居。尝试在设计器中构建它,在那里你可以看到发生了什么以及生成了什么代码。
-
谢谢,现在我对布局有了更深入的了解。