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. Can't get rid of spacing between two widgets in QSplitter
Qt 6.11 is out! See what's new in the release blog

Can't get rid of spacing between two widgets in QSplitter

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 585 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by
    #1

    Here is my problem:
    alt text
    I need the blue and green widgets to touch.

    Inbetween both is a QSplitterHandle that I deactivated and set the fixed width to 0.
    I know the handle has a width of 0, because I set its background-color to red and it doesn't show up. The splitter's and both widget's content margins are set to 0.

        QWidget *p_menu_icons_widget = new QWidget;
        p_menu_icons_widget->setContentsMargins(5, 5, 0, 5); // Right margin 0
        p_menu_icons_widget->setLayout(p_menu_icons_layout);
        p_menu_icons_widget->setStyleSheet("background-color: blue;");
    
        QWidget *p_menu_list_widget = new QWidget;
        p_menu_list_widget->setContentsMargins(0, 5, 5, 5); // Left margin 0
        p_menu_list_widget->setLayout(p_menu_list_layout);
        p_menu_list_widget->setStyleSheet("background-color: green;");
    
        m_p_main_splitter = new QSplitter;
        m_p_main_splitter->addWidget(p_menu_icons_widget);
        m_p_main_splitter->addWidget(p_menu_list_widget);
        m_p_main_splitter->setContentsMargins(0, 0, 0, 0);
        m_p_main_splitter->handle(1)->setEnabled(false);
        m_p_main_splitter->handle(1)->setFixedWidth(0); // hide() doesn't work.
        m_p_main_splitter->handle(1)->setStyleSheet("background-color: red;");
    

    Still, there is this spacing between them.
    What am I forgetting?

    Chris KawaC 1 Reply Last reply
    0
    • qwasder85Q qwasder85

      Here is my problem:
      alt text
      I need the blue and green widgets to touch.

      Inbetween both is a QSplitterHandle that I deactivated and set the fixed width to 0.
      I know the handle has a width of 0, because I set its background-color to red and it doesn't show up. The splitter's and both widget's content margins are set to 0.

          QWidget *p_menu_icons_widget = new QWidget;
          p_menu_icons_widget->setContentsMargins(5, 5, 0, 5); // Right margin 0
          p_menu_icons_widget->setLayout(p_menu_icons_layout);
          p_menu_icons_widget->setStyleSheet("background-color: blue;");
      
          QWidget *p_menu_list_widget = new QWidget;
          p_menu_list_widget->setContentsMargins(0, 5, 5, 5); // Left margin 0
          p_menu_list_widget->setLayout(p_menu_list_layout);
          p_menu_list_widget->setStyleSheet("background-color: green;");
      
          m_p_main_splitter = new QSplitter;
          m_p_main_splitter->addWidget(p_menu_icons_widget);
          m_p_main_splitter->addWidget(p_menu_list_widget);
          m_p_main_splitter->setContentsMargins(0, 0, 0, 0);
          m_p_main_splitter->handle(1)->setEnabled(false);
          m_p_main_splitter->handle(1)->setFixedWidth(0); // hide() doesn't work.
          m_p_main_splitter->handle(1)->setStyleSheet("background-color: red;");
      

      Still, there is this spacing between them.
      What am I forgetting?

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      setEnabled(false) does not remove the handle. It just makes a widget not interactive (grayed out).
      Resizing the handle doesn't resize the space allocated for it by the widget.

      You should not fiddle with the handle directly. QSplitter has a setHandleWidth() method that changes the size of the handle. Depending on the style used it might not let you go all the way down to 0. The point of a splitter is that there's some indication to the user that they can grab it. If you just want two widgets side by side then put them in a horizontal layout without spacing.

      qwasder85Q 1 Reply Last reply
      2
      • Chris KawaC Chris Kawa

        setEnabled(false) does not remove the handle. It just makes a widget not interactive (grayed out).
        Resizing the handle doesn't resize the space allocated for it by the widget.

        You should not fiddle with the handle directly. QSplitter has a setHandleWidth() method that changes the size of the handle. Depending on the style used it might not let you go all the way down to 0. The point of a splitter is that there's some indication to the user that they can grab it. If you just want two widgets side by side then put them in a horizontal layout without spacing.

        qwasder85Q Offline
        qwasder85Q Offline
        qwasder85
        wrote on last edited by
        #3

        @Chris-Kawa I guess I should put the left widget outside of the splitter. Thanks.

        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