Unsolved resize parent widget to child widget width
-
i have a dialog which has a child widget table view.
some of table items are long, so when the table view is updated due to insertion of the item in model, the table resizes, because i have set this:
m_pTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
.but then my dialog (parent widget) doesn't resize itself so i get dialog with only part of the table widget visualized. i want to have the dialog also to be resized so i can have a complete view.
what should i do?
-
@user4592357 said in resize parent widget to child widget width:
what should i do?
Add a proper layout to your dialog. See also https://doc.qt.io/qt-5/layout.html
-
@Christian-Ehrlicher
the table view and other items i dialog are inserted in layout -
@user4592357 said in resize parent widget to child widget width:
the table view and other items i dialog are inserted in layout
So what do you want to achieve? Automatically resize the whole dialog? This would irritate the user I would guess.
-
@Christian-Ehrlicher
the dialog is initialized once, and user has to check items in it, so there's no more insertions after initialisation. so it'll be just one resize of the whole dialog. -
So retrieve the viewport size and resize the dialog accordingly
-
@Christian-Ehrlicher
okay. i have two columns actually, one is for text which can be long, and one is for icon, fixed size. and dialog has ability to filter from table rows. so when i type text of small item, only that small item is shown, and the first column resizes to width of that text. how can i always keep the width of first column the width of longest text in model? -
-
@Christian-Ehrlicher
i did this after init but the dialog is now too narrow:auto pViewport = m_pTableView->viewport(); setFixedWidth(pViewport->width());