Results 1 to 4 of 4

Thread: How to avoid a widget to be affected by a layout ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to avoid a widget to be affected by a layout ?

    I have the typical layout_vertical thats adjust the vertical size of a layout_horizontal whre I have the widgets distributed.
    Ok, now I'd want to have a independent widget 'floating' , but I dont know how to do the work. If I set layout_vertical for the main Widget, the floating widget is affected.
    Any idea ?
    Thanks

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to avoid a widget to be affected by a layout ?

    if you want the widget to be floating, don't add to the layout, just create the widget with a parent widget (the widget you want to place it on), and call show() to make it visible, and call setGeometry() to set the floating position, which is relative to the parent.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to avoid a widget to be affected by a layout ?

    Thanks.
    The problem is related with Designer.
    Ok, I have a pure QWidget.
    I have 1.- a List 2.- a Treeview. I want to apply a horizontal layout to this two elements, givin (in example ) 200 pixels max to treeview. I select the 2 components and click on 'layout Horizontally".Ok, my horizontal resize runs ok.

    I have my third element, a 'floating' widget that I have placed in no particular place, in example, at the bottom -left.
    Next, I want to let automatic vertical resize for my 2 main componentes (the list and the treeview), so on the main Widget I choose layout vertically.

    The problem was that this layout is applying to the layout_horizontal and my_floating widget.
    And I dont know how to fix this problem ?
    The solution can be a bool 'float' property that does not exist. ( to tell layout that a widget with this property set to true is not part of the world to adjust )
    Thanks

  4. #4
    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: How to avoid a widget to be affected by a layout ?

    The solution can be a bool 'float' property that does not exist.
    It does exist - explicitly.
    As Santosh Reddy already said, if you want a widget not to be managed by a layout, just keep that widget out of a layout, this is your bool - the layout will only manage widgets that are added to it.

    so on the main Widget I choose layout vertically.
    By this you are adding ALL the widgets on the forum to this layout, including your third widget which until now was not in a layout.
    Instead of adding the layout to whole form, selct only the widgets/laouts you want to manage with this layout.
    ==========================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. mainwindow layout vs widget layout
    By fatecasino in forum Newbie
    Replies: 2
    Last Post: 14th December 2010, 14:45
  2. Avoid the qt_flush on my main widget
    By kinju in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2010, 13:15
  3. How to change a widget to other widget in layout?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 10:55
  4. How can I avoid the paintEvent after resizing a widget?
    By jianliang79 in forum Qt Programming
    Replies: 11
    Last Post: 11th September 2009, 01:26
  5. Avoid widget in taskbar
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2008, 22:18

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
  •  
Qt is a trademark of The Qt Company.