Nominate our 2022 Qt Champions!

Resize dialog when it's child table resizes

  • I've got dialog in *.ui file, which contains some children like: labels, comboboxes, etc. Most place is taked by QTableWidget. When I change count of rows(columns) in it, it automatically shows sliders to scroll the content. But I need other thing: If my table gets bigger I need to resize my parent widget (QDialog) to sizes when all content of my table is shown, and if table gets smaller leave existing sizes.

  • Use layout and signal/slot. But i think the common way is resize the dialog, and then the table's size changes

  • I already apply layouts but for table it has no effect. What signals and slots you mean ? Of-course it changes when the dialog has been resized, but I don't know how much bigger I must make my dialog, to all content of table has been shown.

  • What do you want to happen when you reach or exceed the screen height?

  • Have you tried to set the scrollbar policy of the table widget to always off?

  • to ludde: I'll tried to do this:--
    m_ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @
    But I only lost my scrolls without any resizes.

  • This code from
    [quote author="dakron" date="1310030727"]Anticross: look at "this":[/quote]

    @ QRect rect = m_ui->tableWidget->geometry();
    rect.setWidth(2 + m_ui->tableWidget->verticalHeader()->width() +
    m_ui->tableWidget->columnWidth(0) + m_ui->tableWidget->columnWidth(1) + m_ui->tableWidget->columnWidth(2));

    Has bad results. I've got Half of my table shown in dialog after calling adjust size.

  • [quote author="ZapB" date="1310029477"]What do you want to happen when you reach or exceed the screen height?[/quote]

    Nothing, I just want to resize by calling some function in class which using my *.ui, and if it reach screen size user can manually resize dialog.

  • And how do they do that if the bottom edge of the window is off the bottom edge of the screen? Why not just let the user manage the window size like nearly every other application does. I do not understand your use case I guess. Could you elaborate as to why you want to do this please?

  • First thing - user can fit window to screen size by clicking on OS toolbar and choosing fit_to_window. I need it because my table have some number presets, I mean I have logically many tables of different sizes, and The data which contains on it is visually perceptible better when all table shown, not the part of it. And also these tables are not so big to occupy all screen.(but of-course you right that I need to proceed this situation too).

  • If you are sure you want to go down this route then I think probably your best option is to subclass QTableView and override the sizeHint stuff so that the table returns sizehints suitable for the contents they are showing. The Qt layout system should then take care of the rest of it for you.

    That is not to say that calculating suitable size hints will be easy. You will need to query things like number of rows and their sizes (or are they all the same size), style metrics (since different styles have different size requirements), margins, font sizes etc.

Log in to reply