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. QSplitter collapses widget directly when the widget size is below a given size
QtWS25 Last Chance

QSplitter collapses widget directly when the widget size is below a given size

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.4k Views
  • 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.
  • O Offline
    O Offline
    odelaune
    wrote on last edited by
    #1

    Hello, in my MainWindow, I have a spliter in which I placed two widgets (see the picture below)
    widget_collapse.png

    Currently, when a suer resize the blue part, its size goes to 0 and the the QSplitter collapses the blue widget.
    I tried to use setCollapsible(false) for the blue widget but in that case, the widget is not collapsed anymore ; it stops resizing below a minimum size.

    What I would like is the blue widget cannot be smaller than the "minimum size before collapsing" shown on the picture and if the user continue to resize lower, then the widget collapse. Another way to say is I would like the collapsing happens if the widget size is smaller than a given size.

    Any idea?

    Gojir4G 1 Reply Last reply
    0
    • O odelaune

      Hello, in my MainWindow, I have a spliter in which I placed two widgets (see the picture below)
      widget_collapse.png

      Currently, when a suer resize the blue part, its size goes to 0 and the the QSplitter collapses the blue widget.
      I tried to use setCollapsible(false) for the blue widget but in that case, the widget is not collapsed anymore ; it stops resizing below a minimum size.

      What I would like is the blue widget cannot be smaller than the "minimum size before collapsing" shown on the picture and if the user continue to resize lower, then the widget collapse. Another way to say is I would like the collapsing happens if the widget size is smaller than a given size.

      Any idea?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @odelaune Try setting the minimum size ( or minimum width) on the blue widget.

      O 1 Reply Last reply
      1
      • Gojir4G Gojir4

        @odelaune Try setting the minimum size ( or minimum width) on the blue widget.

        O Offline
        O Offline
        odelaune
        wrote on last edited by odelaune
        #3

        @Gojir4
        Here is what I have so far

           int appWidth = QGuiApplication::primaryScreen()->virtualSize().width();
           ui->splitter->setSizes(QList<int>({appWidth*2/3 , appWidth*1/3}));
        
           ui->blue_area->setMinimumWidth(200);
           ui->blue_area->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
        

        Unfortunately, it does not change anything. Actually, the widget collapses directly when its width is smaller than 50 pixels. But I do not have any 50 pixels in my code.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          odelaune
          wrote on last edited by
          #4

          Small clarification: my blue widget is actually a QTabWidget. Is there any special with this QWidget?

          Gojir4G 1 Reply Last reply
          0
          • O odelaune

            Small clarification: my blue widget is actually a QTabWidget. Is there any special with this QWidget?

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #5

            @odelaune Not sure but if the QTabWidget is empty it may have a sizeHint of 0, maybe it has "priority" over minimumSize. Hard to say without testing. So I would test with simple QWidget instead of QTabWidget to see if there is a difference. What I'm doing usually in this case is making some experiment in the Qt designer until I find the good configuration.

            JonBJ 1 Reply Last reply
            1
            • Gojir4G Gojir4

              @odelaune Not sure but if the QTabWidget is empty it may have a sizeHint of 0, maybe it has "priority" over minimumSize. Hard to say without testing. So I would test with simple QWidget instead of QTabWidget to see if there is a difference. What I'm doing usually in this case is making some experiment in the Qt designer until I find the good configuration.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Gojir4 said in QSplitter collapses widget directly when the widget size is below a given size:

              What I'm doing usually in this case is making some experiment in the Qt designer until I find the good configuration.

              Well said!

              1 Reply Last reply
              0
              • O Offline
                O Offline
                odelaune
                wrote on last edited by odelaune
                #7

                Some news. I played with Qt Designer and it appears that my custom widget (blue part) has a good behaviour when I set a minimum width for it with setMinimumWidth(), i.e. it collapses when its width becomes smaller than the minimum width . Yet, when I place this custom widget in a QTabWidget, then I have my initial problem, i.e. the blue part (that is now a QTabWidget) collapses only when its width becomes smaller than 50 pixels, even if I set its minimum width to 200 pixels.

                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