PDA

View Full Version : QDialog resize ?



allensr
10th December 2007, 22:31
I have a QDialog that I'm using to display a tableWidget. The tableWidget contents are the result of a database query. In another dialog the user selects a series of checkboxes that ultimatley determines the query and each checkbox represents a column from a database table. So, I made the QDialog box that holds the tableWidget really wide but depending on which checkboxes the user clicks, I may only display 1 column or up to 10 columns. My question is, how do I programatically set the Dialog's width based on the width of the tableWidget? When I only have a few columns to display there's a lot of white space to the right of the last column.

TIA.

wysota
11th December 2007, 00:28
QWidget::resize() is a nice way to change the size of a widget and to calculate the proper width you'll have to fetch the header of the table, calculate the width of all columns based on the header, add the frame of the view to the result, add the margin between the dialog border and the view, add the width of the dialog border and set that as the width of the dialog. Or you can set the size of the table widget in a similar manner (without everything that is related to the dialog) and put a constraint on the dialog's layout so that its size is fixed on its contents size.

allensr
11th December 2007, 16:46
OK, thanks. But I'm a little unclear on how the best way to get the "width of all columns based on the header, add the frame of the view to the result, add the margin between the dialog border and the view, add the width of the dialog border".

wysota
11th December 2007, 16:47
Have you seen QHeaderView docs?

allensr
11th December 2007, 17:09
OK, got the headerView->length(). What about the other 3 parameters you mentioned (add the frame of the view to the result, add the margin between the dialog border and the view, add the width of the dialog border)?

wysota
11th December 2007, 19:47
I'm not sure length() is what you are after. It depends on how your view is set up. Other parameters need to be gathered from different classes - the layout, the style and the widget. I suggest you try a simpler approach - by setting the size of the table widget and forcing the dialogs layout to adjust to it. You'll just need the frame size then.