How can I add resizable widgets in Qt Creator?

时间秒杀一切 提交于 2019-12-01 11:58:57

问题


How can I add resizable widgets in Qt Creator?

Specially widgets in QVBoxLayout or QHBoxLayout


回答1:


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();
}



回答2:


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



来源:https://stackoverflow.com/questions/7195781/how-can-i-add-resizable-widgets-in-qt-creator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!