13

I want to initialize the splitter handle position like the following instead of in the middle. I cannot set it in the property.

enter image description here

How to solve this?

Casper
  • 4,435
  • 10
  • 41
  • 72

4 Answers4

17

You can use QSplitter::setSizes in this why to reposition the handle:

ui->splitter->setSizes(QList<int>() << 100 << 200);
Nejat
  • 31,784
  • 12
  • 106
  • 138
ahmed
  • 5,430
  • 1
  • 20
  • 36
15

You should set the horizontal stretch for the two widgets in the splitter. For instance by setting the horizontal stretch of the left widget to 1 and the right widget to 2, the right widget gets a width 2 times the left one :

leftWidget->sizePolicy().setHorizontalStretch(1);
rightWidget->sizePolicy().setHorizontalStretch(2); 

Another possible way is to use QSplitter::setSizes.

Nejat
  • 31,784
  • 12
  • 106
  • 138
6

Use QSplitter::setStretchFactor(int index, int stretch) where index is the position of the respective widget.

Tobias Leupold
  • 1,512
  • 1
  • 16
  • 41
0

i was having the same issue but ull find a predefined attribute existing called

`self.horizontalLayout_6.setSpacing(0)` 

u will also find a

  self.verticalLayout_6.setSpacing(0)

u can change the spacing to whatever u like it worked for me

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 10 '23 at 09:26