Qt World Summit: Register Today!

How to resize the application with different screen sizes?

  • I want to automatically resize my application with different screen sizes, I have a StackedWidget in the app,
    From this link I assign grid layout to the central widget. , Which has Automatic resizing with different screen size,but content of it doesn't resize
    0_1559367264899_Screenshot from 2019-06-01 09-45-12.png

    I add the grid layout on each page of stackWidget but the button,lineEdit,.... get too wide and
    Cannot resize or change location of it
    0_1559367298504_Screenshot from 2019-06-01 10-01-24.png

    With assign grid layout on central widget all content of it should be get layout?
    How do I assign layouts to pages that can resize the qlineEdit, button ...?!

  • Lifetime Qt Champion

    You are doing it right,
    however, both QLineEdit and QPushButton have Fixed policy as default
    alt text
    preventing them from growing/use all space.

    alt text

    If you do
    alt text
    then they grow
    alt text

    Anyway, you need both layout on CentralWidget to size the stackedwidget and then
    on each page, you also need a layout. (which you seem to do )

  • @mrjj tnx

  • When I using buttons, lineEdits, labels, comboBox on a page, for example, I use 30 items in grid layout and run the program with xcb platform, in raspberry pi with a 800 x 480 display(5inch) , This will cause the app's page to be dragged down and right and not everything show completely the window minimize,closer button is not specified. But When I use fewer items, it's okay,
    I need to use 30 items in one page how can I fixed the program size ?
    I use this in main.cpp:

    QRect rec = QApplication::desktop()->screenGeometry();
       int height1 = rec.height();
       int width1 = rec.width();

    and this in mainWindow.cpp:

                    "#centralWidget { "
                    " border-image: url(:/new/prefix1/Untitled-7.jpg) 0 0 0 0 stretch stretch;"

  • Lifetime Qt Champion


    Why not use showFullScreen directly ?

    What are these 30 items ? It's quite a lot on a small screen.

    You might want to consider using QScrollArea to allow your user to scroll up and down to see your widgets.

    Depending on your application, you might wan to break down your UI in smaller elements.

  • This post is deleted!

Log in to reply