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. How to prevent QSplitter child from collapsing before completely minimizing its size to 0?
Forum Updated to NodeBB v4.3 + New Features

How to prevent QSplitter child from collapsing before completely minimizing its size to 0?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 657 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.
  • C Offline
    C Offline
    CPPUIX
    wrote on last edited by CPPUIX
    #1

    Hi,

    I'm trying to get a horizontal QSplitter to allow me to resize one of its children's width to 0 without it collapsing before reaching the edge.

    Here's an example of QSplitter with 2 children, a QWidget, and a QPushButton, where the button collapses before I drag it to the edge:

    Unwanted collapsing behavior

    Minimal Reproducible example:

    QSplitter *splitter = new QSplitter();
    QWidget *widget = new QWidget;
    QPushButton *button = new QPushButton("button");
    
    widget->setStyleSheet("background: darkblue;");
    
    splitter->addWidget(button);
    splitter->addWidget(widget);
    
    splitter->show();
    
    splitter->setMinimumSize(100,100);
    

    I tried:

    • setChildrenCollapsible(false), but it results in the button not not budging below a certain width, here's how it looks:

      Button not budging

    • Setting minimum width of QSplitter and its children to 0, setting their sizes manually below the size it won't go below, changing size policy to ignored, but it made no difference.

    Using an event filter, I noticed a QInputMethodQueryEvent triggered when the button collapses, but I do not know how to use that.

    I also noticed that the behavior I'm looking to achieve is possible with QWidget, QFrame, here's how it looks with 2 QWidgets in a QSplitter:

    Normal collapsing behavior

    Based on this observation, I managed to find a workaround, by placing the widget I need (button for example) inside a QWidget, and making the container widget a child of QSplitter, and it works, but I'd rather avoid using this method.

    What is causing this behavior? And how do I change it so that the button resizes until its width reaches 0 without collapsing?

    Thank you for your time, effort and interest!

    JoeCFDJ 1 Reply Last reply
    0
    • JoeCFDJ JoeCFD

      @Abderrahmene_Rayene This is interesting. Maybe you can print out the stylesheets of qpushbutton and qwidget as its container. You may be able to see some differences.

      C Offline
      C Offline
      CPPUIX
      wrote on last edited by CPPUIX
      #10

      @JoeCFD Someone on SO suggested to set horizontal size policy of the button to Ignored, and it worked. Problem solved.

      Thanks for your time and input!

      1 Reply Last reply
      1
      • C CPPUIX

        Hi,

        I'm trying to get a horizontal QSplitter to allow me to resize one of its children's width to 0 without it collapsing before reaching the edge.

        Here's an example of QSplitter with 2 children, a QWidget, and a QPushButton, where the button collapses before I drag it to the edge:

        Unwanted collapsing behavior

        Minimal Reproducible example:

        QSplitter *splitter = new QSplitter();
        QWidget *widget = new QWidget;
        QPushButton *button = new QPushButton("button");
        
        widget->setStyleSheet("background: darkblue;");
        
        splitter->addWidget(button);
        splitter->addWidget(widget);
        
        splitter->show();
        
        splitter->setMinimumSize(100,100);
        

        I tried:

        • setChildrenCollapsible(false), but it results in the button not not budging below a certain width, here's how it looks:

          Button not budging

        • Setting minimum width of QSplitter and its children to 0, setting their sizes manually below the size it won't go below, changing size policy to ignored, but it made no difference.

        Using an event filter, I noticed a QInputMethodQueryEvent triggered when the button collapses, but I do not know how to use that.

        I also noticed that the behavior I'm looking to achieve is possible with QWidget, QFrame, here's how it looks with 2 QWidgets in a QSplitter:

        Normal collapsing behavior

        Based on this observation, I managed to find a workaround, by placing the widget I need (button for example) inside a QWidget, and making the container widget a child of QSplitter, and it works, but I'd rather avoid using this method.

        What is causing this behavior? And how do I change it so that the button resizes until its width reaches 0 without collapsing?

        Thank you for your time, effort and interest!

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #2

        @Abderrahmene_Rayene set minimum width of button to 0? Its minimum width may not be 0 because it has text.

        C 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          @Abderrahmene_Rayene set minimum width of button to 0? Its minimum width may not be 0 because it has text.

          C Offline
          C Offline
          CPPUIX
          wrote on last edited by
          #3

          @JoeCFD I did try that, and using a button with no text, same result unfortunately.

          JoeCFDJ 1 Reply Last reply
          0
          • C CPPUIX

            @JoeCFD I did try that, and using a button with no text, same result unfortunately.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #4

            @Abderrahmene_Rayene https://stackoverflow.com/questions/6639012/minimum-size-width-of-a-qpushbutton-that-is-created-from-code

            C 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Abderrahmene_Rayene https://stackoverflow.com/questions/6639012/minimum-size-width-of-a-qpushbutton-that-is-created-from-code

              C Offline
              C Offline
              CPPUIX
              wrote on last edited by CPPUIX
              #5

              @JoeCFD Thanks for the link

              I was already setting its minimum width explicitly as follows:

              button->setMinimumWidth(0);

              and just to check if it is actually set, I used this:

              button->connect(button,&QPushButton::clicked,[button]()
              { 
                  button->setMinimumWidth(0); 
                  qDebug()<<button->minimumWidth(); 
                  qDebug()<<button->size();
              });
              

              I resized the button and clicked it to check its size multiple times, it is not arbitrary, and the minimum width is set to 0. I'm not sure this is the correct way to check it, but that's what could think of

              I tried the other answer, but same result, the only difference is that it made its size smaller when I used no text, but the "snappy" collapsing still occurs without text.

              JoeCFDJ 1 Reply Last reply
              0
              • C CPPUIX

                @JoeCFD Thanks for the link

                I was already setting its minimum width explicitly as follows:

                button->setMinimumWidth(0);

                and just to check if it is actually set, I used this:

                button->connect(button,&QPushButton::clicked,[button]()
                { 
                    button->setMinimumWidth(0); 
                    qDebug()<<button->minimumWidth(); 
                    qDebug()<<button->size();
                });
                

                I resized the button and clicked it to check its size multiple times, it is not arbitrary, and the minimum width is set to 0. I'm not sure this is the correct way to check it, but that's what could think of

                I tried the other answer, but same result, the only difference is that it made its size smaller when I used no text, but the "snappy" collapsing still occurs without text.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #6

                @Abderrahmene_Rayene Try also to set minimumSizeHint = 0?
                or use QToolButton? Or create your own push button.

                C 1 Reply Last reply
                0
                • JoeCFDJ JoeCFD

                  @Abderrahmene_Rayene Try also to set minimumSizeHint = 0?
                  or use QToolButton? Or create your own push button.

                  C Offline
                  C Offline
                  CPPUIX
                  wrote on last edited by CPPUIX
                  #7

                  @JoeCFD Same thing, I'm thinking every compound widget behaves like this in a QSplitter (QTextEdit, QComboBox...), but as I've mentioned, if I place them in a container QWidget, I get the desired result (no snappy collapsing), I don't understand why, but it seems this is the only possible solution.

                  I thought about sub-classing the widgets I want to use, and somehow resize them before they collapse, I'm not sure this even works, and it seems like too much trouble and chaos compared to the container method.

                  P.S: Sorry if me using a button is misleading, I'm just using it as an example.

                  JoeCFDJ 1 Reply Last reply
                  0
                  • C CPPUIX

                    @JoeCFD Same thing, I'm thinking every compound widget behaves like this in a QSplitter (QTextEdit, QComboBox...), but as I've mentioned, if I place them in a container QWidget, I get the desired result (no snappy collapsing), I don't understand why, but it seems this is the only possible solution.

                    I thought about sub-classing the widgets I want to use, and somehow resize them before they collapse, I'm not sure this even works, and it seems like too much trouble and chaos compared to the container method.

                    P.S: Sorry if me using a button is misleading, I'm just using it as an example.

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by
                    #8

                    @Abderrahmene_Rayene This is interesting. Maybe you can print out the stylesheets of qpushbutton and qwidget as its container. You may be able to see some differences.

                    C 2 Replies Last reply
                    1
                    • JoeCFDJ JoeCFD

                      @Abderrahmene_Rayene This is interesting. Maybe you can print out the stylesheets of qpushbutton and qwidget as its container. You may be able to see some differences.

                      C Offline
                      C Offline
                      CPPUIX
                      wrote on last edited by
                      #9

                      @JoeCFD Oh interesting, didn't cross my mind, I'll try it and report back. Thanks!

                      1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @Abderrahmene_Rayene This is interesting. Maybe you can print out the stylesheets of qpushbutton and qwidget as its container. You may be able to see some differences.

                        C Offline
                        C Offline
                        CPPUIX
                        wrote on last edited by CPPUIX
                        #10

                        @JoeCFD Someone on SO suggested to set horizontal size policy of the button to Ignored, and it worked. Problem solved.

                        Thanks for your time and input!

                        1 Reply Last reply
                        1
                        • C CPPUIX has marked this topic as solved on

                        • Login

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