Results 1 to 2 of 2

Thread: Properly show dynamically added widgets

  1. #1
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Properly show dynamically added widgets

    Hi,

    When I create a QWidget which contains a QVBoxLayout and I add another QWidget (with contents) inside of it and never change this, everything works as expected.
    It is shown correctly (the sizes are correct) and it can be resized without problems (it expands).

    But when I do not add the inner QWidget initially to the layout (before everything is shown the first time) and only add it later on when the program is already running and shown, the widget does not show unless I explicitly call setMinimumSize (or setFixedSize). Also it does not expand anymore when I resize the program.

    What steps are needed to make it automatically show and resize when added dynamically during runtime (after the initial show)? (Something with SizeHints or ...?)
    The functions update, show, updateGeometry, etc ... don't seem to be enough.
    ("If you add a child widget to an already visible widget you must explicitly show the child to make it visible" -> text from the documentation but this does not seem to be enough)

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Properly show dynamically added widgets

    It could be that it is being added, and shown, but 0 or 2 pixel size.
    It depends on the layout policies, and on the widgets size policies and constraints.
    If you share the relevant code it might be easier to help.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 5
    Last Post: 22nd December 2016, 23:04
  2. Get name of QAction from Menu when dynamically added
    By yapatel in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2014, 09:16
  3. Replies: 5
    Last Post: 10th March 2014, 06:40
  4. Replies: 2
    Last Post: 3rd June 2013, 17:45
  5. Connecting dynamically added properties
    By stefkeB in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2008, 16:19

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.