Results 1 to 3 of 3

Thread: set dialog size to fit contents after dynamically add widjets

  1. #1
    Join Date
    Jan 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default set dialog size to fit contents after dynamically add widjets

    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
    NormilizeDialog.jpg

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: set dialog size to fit contents after dynamically add widjets

    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. Your dialog is basically the same as this - different widgets, but still the same solutions regarding the layouts.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Question Re: set dialog size to fit contents after dynamically add widjets

    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 :
    NormilizeDialog_question2_start.jpg

    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:
    NormilizeDialog_question2_end.jpg

    The code of the dynamically created widgets is
    Qt Code:
    1. class NormalizeDialog(QDialog, Ui_NormalizeDialog):
    2. """description of class"""
    3. def __init__(self, parent, inputMatrix):
    4. QDialog.__init__(self, parent)
    5. self.setupUi(self)
    6. self.inputMatrix = inputMatrix
    7. self.initNormilizeInput()
    8. self.setLayout(self.verticalLayout_2)
    9. self.adjustSize()
    10.  
    11. def initNormilizeInput(self):
    12. for fieldName in self.inputMatrix[0]:
    13. normalizeInput = NormalizeInput(self, fieldName)
    14. normalizeInput.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored)
    15. self.verticalLayout.addWidget(normalizeInput)
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Replies: 2
    Last Post: 6th October 2015, 18:20
  2. How to adapt the size of QWebView to its contents
    By mycityofsky in forum Qt Programming
    Replies: 0
    Last Post: 28th May 2015, 15:39
  3. How to make Dialog fit it's contents?
    By flashmozzg in forum Qt Quick
    Replies: 5
    Last Post: 12th May 2015, 07:53
  4. Replies: 0
    Last Post: 14th February 2012, 15:43
  5. How can i get the contents size of QTextBrowser
    By m_e in forum Qt Programming
    Replies: 4
    Last Post: 25th December 2006, 14:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.