How can I add resizable widgets in Qt Creator?

2019-02-20 14:35发布

How can I add resizable widgets in Qt Creator?

Specially widgets in QVBoxLayout or QHBoxLayout

2条回答
贼婆χ
2楼-- · 2019-02-20 15:02

Example:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QWidget* w = new QWidget;
    QVBoxLayout* l = new QVBoxLayout;
    w->setLayout(l);
    QPushButton* b = new QPushButton("hello");
    b->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    l->addWidget(b);
    w->show();    

    return app.exec();
}
查看更多
贪生不怕死
3楼-- · 2019-02-20 15:02

You must use layouts if you want that your widgets are resizable: http://doc.qt.io/qt-5/layout.html

查看更多
登录 后发表回答