PDA

View Full Version : QSplitter like a "grid" splitter [Using qt 4.4]



yandy
19th March 2009, 04:27
Hi,

my problem is the following

I have several widgets I want to layout in a grid style and I also want to
have the QSplitter sizing features.

With QSplitter i only can layout the widgets horitzontally or vertically but
not in a grid with a handle in the centre to resize the widgets at the same
time.

For example, if I have 4 widgets like this picture

(such as 1.png in attachment)

if I move the handle in the centre to the right then

(such as 2.png in attachment)

if I move the handle in the centre down then

(such as 3.png in attachment)

I've seen this kind of feature in some windows app's but I don't know if
this is possible using qt 4.1.

I would like to know if there's a way to do that with the actual
QSplitter's. Although if somenone has tried something similar and can give
some hints to do it with another classes to get a similar result

Thanks.

Lykurg
19th March 2009, 07:16
We also can read small texts!

In one orientation you have one QSpliter in the other you have two.
QSplitter s1 = new QSplitter(Qt::Horizontal);
QSplitter s2 = new QSplitter(Qt::Horizontal);
// add 2 widgets to each of them
QSplitter s3 = new QSplitter(Qt::Vertical);
s3->addWidget(s1);
s3->addWidget(s1);

Now connect s1 and s2: sX::splitterMoved( int pos, int index ) to sY->handle(index)::moveSplitter(pos). (and vice versa!)

Not tested but should work.

yandy
19th March 2009, 12:06
We also can read small texts!

In one orientation you have one QSpliter in the other you have two.
QSplitter s1 = new QSplitter(Qt::Horizontal);
QSplitter s2 = new QSplitter(Qt::Horizontal);
// add 2 widgets to each of them
QSplitter s3 = new QSplitter(Qt::Vertical);
s3->addWidget(s1);
s3->addWidget(s1);

Now connect s1 and s2: sX::splitterMoved( int pos, int index ) to sY->handle(index)::moveSplitter(pos). (and vice versa!)

Not tested but should work.
Thank you for your reply.But,maybe, I haven't expressed my problem properly. I'd like to move the point at the cross centre of the 4 splitter widgets to resize all of them four at the same time.Not just move "up to down" or "left to right". Thanks

Lykurg
19th March 2009, 12:25
then extend the sample by an own splitter handle for s3 (painted at the position of the handles s1/s2). Use mouse tracking to get the coordinates and emit proper signals which are connected to s1 and s2. Pack all in one widget with an function setWidgetInSplitter(...).
Easy :cool:

yandy
19th March 2009, 12:57
then extend the sample by an own splitter handle for s3 (painted at the position of the handles s1/s2). Use mouse tracking to get the coordinates and emit proper signals which are connected to s1 and s2. Pack all in one widget with an function setWidgetInSplitter(...).
Easy :cool:

Thank you,Let me have a try

Lykurg
19th March 2009, 13:33
Let me have a try
Go on, that's some work to get thinks work right. When you are ready, share your knowledge with us :)

wayfaerer
21st March 2012, 21:48
In one orientation you have one QSpliter in the other you have two.
QSplitter s1 = new QSplitter(Qt::Horizontal);
QSplitter s2 = new QSplitter(Qt::Horizontal);
// add 2 widgets to each of them
QSplitter s3 = new QSplitter(Qt::Vertical);
s3->addWidget(s1);
s3->addWidget(s1);

Now connect s1 and s2: sX::splitterMoved( int pos, int index ) to sY->handle(index)::moveSplitter(pos). (and vice versa!)

Not tested but should work.

This is an old thread, but I don't quite understand Lykurg's suggestion. moveSplitter() is a member of QSplitter, not QSplitterHandle. Further, it's a protected function. So I can't figure out how to get it to work. Any ideas?

Lykurg
22nd March 2012, 06:42
You could subclass it to access it, but you don't need it. It was mainly an example on how to do it theoretical. Use QSplitter::setSizes() to set the size of the spliter. (for that you have to create a custom slot!)

void slotForS2Moved() {
s1->setSizes(s2->sizes());
}