Can't get rid of spacing between two widgets in QSplitter
-
Here is my problem:

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? -
Here is my problem:

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?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.
-
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.
@Chris-Kawa I guess I should put the left widget outside of the splitter. Thanks.