Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Making a Qwidget, in no layout but with a layout in it, stay at its minimum size
Forum Updated to NodeBB v4.3 + New Features

Making a Qwidget, in no layout but with a layout in it, stay at its minimum size

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hans977
    wrote on last edited by
    #1

    I have a window level widget that has no layout. Items are added to it when and where the user click on it.

    The item placed on the main window is derived from a Qwidget and has a QHboxLayout in it. I will call it “the item”. “The item” has three things in its QHboxLayout: A label and two custom widgets that stay small.

    The question is how do I make “the item” stay as small as it can given its content. When I click on the window widget it places “the item” there but it is many times larger than it needs to be to hold the tree items in it.

    I tried to make a custom QHBoxLayout:
    @
    QSize maximumSize() const {
    return minimumSize();
    }

    QSize sizeHint() const {
        return minimumSize();
    }@
    

    I also tried to set the layout to minimum size..

    @layout->setSizeConstraint(QLayout::SetMinimumSize);@

    I tried a few other thing but nothing seems to be working. Any ideas what I should try. Thanks

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Sounds like you need to add a spacer item to soak up the additional space horizontally and/or vertically.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hans977
        wrote on last edited by
        #3

        [quote author="ZapB" date="1356128437"]Sounds like you need to add a spacer item to soak up the additional space horizontally and/or vertically.[/quote]

        I do not think that will help since I do not want any additional space in "the item" around its content. I want "the item" to be as small as its contents allows, so the user can place as many of them as possible on the main window. There is no layout on the main window or spacers around items on it.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hans977
          wrote on last edited by
          #4

          I think I figured out something that will work. In “the item's” constructor I set the layouts spacing and contents margins. Then in its paintEvent I call adjustSize(). It seems to be working so far. Thanks

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Can you post a screenshot of what you are trying to achieve please?

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved