2

I have 2 widgets(buttons) in the same splliter and i want to replace the first one with Tabwidget.. i lose the right stretch factor (1:1) it will be like (2:1) or not like the old factor (when it's just 2 buttons)

splitter->addwidget(qbut1);
splitter->addwidget(qbut2);
splitter->insertwidget(0,tab);

and even when i add at the first one tab and one button..tab takes size more than button how can i make it (1:1) i try

splitter->setStretchFactor(0,1);
splitter->setStretchFactor(1,1);

but it doesn't work

  • 1
    May be try `QStackedWidget`/`QStackedLayout`? – Amartel May 29 '15 at 11:57
  • what it helps.. i want to show the both widgets at the same time – Malaz Albawarshi May 29 '15 at 14:50
  • 2Malaz Albawarshi: `i want to replace the first one with Tabwidget` - I referred to this part of your question. You can place first widget on the first page of stacked widget and Tabwidget on the second page. And then just switch between pages. – Amartel Jun 01 '15 at 09:55

1 Answers1

2

You can set the sizes of your splits with QSplitter::setSizes. To achieve a one to one ratio you could use something like this:

int width = splitter->width();
QList<int> sizes;
sizes << width/2 << width/2;
splitter->setSizes(sizes);

Beware that this only sets initial sizes, the user can still resize them at will. Also, re-read the documentation on stretch factors, it sounds as if you may have misunderstood their meaning.

kqt
  • 148
  • 1
  • 8
  • thx for the answer..but why just when i take a widget from a splitter and add it to another i get wrong ration...default is (1,1) when it 's just 2 widgets what i am doing i delete the widget and i add a new one... but i don't want to remove it because i need it's properties – Malaz Albawarshi Jun 01 '15 at 10:54