PDA

View Full Version : set dialog size to fit contents after dynamically add widjets



hindy.ilan@gmail.com
12th January 2017, 15:48
Hi,
I created a dialog using the Qt designer
In the dialog I have several widgets with size policy fixed
And in the middle I have an empty Vertical box layout
all the controls (and the empty box layout) are in vertical box layout
In the application itself I add a customized widget (made of one line of 4 controls) to the empty vertical box layout
When I activated the dialog I saw that the empty (which is now filled) occupy so that it fills the dialog (means that there is vertical space between the widgets I added dynamically)
I want to set the dialog to the size of it's contents
The following is the screen shot
12280

d_stranz
12th January 2017, 20:01
Playing with the "Iris" data set, I see...

Your problem is probably in the way you have specified the layouts for your dialog. Take a look at the Qt Extension example (http://doc.qt.io/qt-5/qtwidgets-dialogs-extension-example.html). Your dialog is basically the same as this - different widgets, but still the same solutions regarding the layouts.

hindy.ilan@gmail.com
14th January 2017, 07:20
I am new in Qt (actually PyQt) and still trying to take it step by step
I will make my question clear

I designed a dialog in the designer which looks like this :
12290

In the initialization I added widgets to an empty vertical box layout found in the middle of the window
After I resize it (manually) it looks like this:
12291

The code of the dynamically created widgets is

class NormalizeDialog(QDialog, Ui_NormalizeDialog):
"""description of class"""
def __init__(self, parent, inputMatrix):
QDialog.__init__(self, parent)
self.setupUi(self)
self.inputMatrix = inputMatrix
self.initNormilizeInput()
self.setLayout(self.verticalLayout_2)
self.adjustSize()

def initNormilizeInput(self):
for fieldName in self.inputMatrix[0]:
normalizeInput = NormalizeInput(self, fieldName)
normalizeInput.setSizePolicy(QSizePolicy.Expanding , QSizePolicy.Ignored)
self.verticalLayout.addWidget(normalizeInput)

So what I am looking for is the following functionality:
- Calculate the height of all the widgets
- activate resize with this height

The code used to create the dynamic widgets is

Second request
Where can I learn (video preffered) about size policy ?

Thank,
Ilan