Re: problem with QSplitter
What is stopping you from resizing the parent window?
1 Attachment(s)
Re: problem with QSplitter
Quote:
Originally Posted by
ChrisW67
What is stopping you from resizing the parent window?
sorry for my unclear explanation.
Actually, "resizing" mentioned above means that dragging the splitter handle and changing its children's width by mouse.
In defalut action of Qsplitter, dragging the splitter handle, one child widget will grow, the other neighbor child widget will shrink, and parent window will keep its width unchanged.
I want, when dragging the handle, one child widget will grow, but the neighbor widget will keep its width, parent window will increase width.
Attachment 9181
Thank you for your reply.
Tang Tao
Re: problem with QSplitter
QSplitter divides the available space (in the container it is in) between the widgets either side of it. It's not capable of changing the size of the outer container. If the user wants a larger window nothing stops them resizing the parent window; this is the standard and expected GUI behaviour.
If you want to code this unusual behaviour yourself then connect to the splitterMoved() signal and programmatically resize the container. Use the splitter stretch factors to ensure all the extra space is placed in the growing widget.
Re: problem with QSplitter
Thanks, ChrisW67
I'll try it. I will post the new problem if I meet trouble with this idea.
Tang Tao
Re: problem with QSplitter
I will not be surprised if resizing the window causes the splitterMoved() signal to fire again in a nasty loop.
1 Attachment(s)
Re: problem with QSplitter
Quote:
Originally Posted by
ChrisW67
I will not be surprised if resizing the window causes the splitterMoved() signal to fire again in a nasty loop.
Hi, ChrisW67
I am glad to hear your far-seeing advice. Why does it cause a nasty loop?
Meanwhile, I'm working on how to get the deltaSize (how far the mouse dragging, or check the image below), which is used for resizing the parent window.
Attachment 9185
Tang Tao
Re: problem with QSplitter
Hi, all
I still have problem with the QSplitter. As described below, I try to get the deltaSize, pls refer to the code below:
Code:
// in Widget.cpp
{
mySplitter = new MySplitter(this);
mySplitter->addWidget(frame1);
mySplitter->addWidget(frame2);
layout->addWidget(mySplitter);
this->setLayout(layout);
this->resize(200, 200);
// always returns (0, 0), I don't know why.
qDebug() << mySplitter->sizes();
}
// in MySplitter.cpp
MySplitter
::MySplitter(Qt
::Orientation ori,
QWidget *parent
):{
if (this->parentWidget() == NULL)
return;
this->setOpaqueResize(false);
this->setChildrenCollapsible(false);
qDebug() << mySplitter->sizes();
originalSizes = this->sizes();
connect(this, SIGNAL(splitterMoved(int,int)), this, SLOT(keepSizeMove(int,int)));
}
void MySplitter::keepSizeMove(int pos, int index)
{
if (this->parentWidget() == NULL)
return;
QList<int> newSizes = this->sizes();
int originalSize = originalSizes.at(index - 1);
int newSize = newSize.at(index - 1);
int deltaSize = newSize - originalSize;
int width = this->parentWidget()->width();
int height = this->parentWidget()->height();
... ...
if (this->orientation() == Qt::Horizontal)
{
this->parentWidget()->resize(width + deltaSize, height);
}
else
{
this->parentWidget()->resize(width, height + deltaSize);
}
this->parentWidget()->repaint();
}
my problem is : "originalSizes" always get (0, 0).
I try to use "setSizes()" and "originalSizes" will get value but a wrong value.(setSizes() fails)
Code:
// in Widget.cpp
{
... ...
this->resize(200, 200);
QList<int>sizes;
sizes << 100 << 100;
mySplitter->setSizes(sizes);
// returns (20, 21), setSizes() fails!
qDebug() << mySplitter->sizes();
}
I googled and found that none had solved yet. (refer to http://www.qtcentre.org/archive/index.php/t-26520.html)
Need help!
Thank you in advance!
Tang Tao
Re: problem with QSplitter
You are constructing your MySplitter instance at line 5 of your first listing. At this point in time it has no widgets to split but you are assuming it does. Until you have added widgets to the splitter and the widget containing the splitter is shown there are no sizes.
Re: problem with QSplitter
Quote:
Originally Posted by
ChrisW67
You are constructing your MySplitter instance at line 5 of your first listing. At this point in time it has no widgets to split but you are assuming it does. Until you have added widgets to the splitter and the widget containing the splitter is shown there are no sizes.
Thank you, ChrisW67! It works! I should call sizes() until the parent widget is shown.
Now, I think I could go on with my work.
Tang Tao