PDA

View Full Version : why the QSplitter cannot show the width as I specified?



superwave
14th July 2011, 02:29
Hi, I have encountered a weird problem:


hctrl = new QTextBrowser();////////////////////////////
hctrl->setReadOnly(TRUE);

hctrl->setFixedHeight(150);

QSplitter* LeftPanel=new QSplitter(Qt::Vertical);
LeftPanel->setFixedWidth(18);
LeftPanel->setFixedHeight(150);

QPushButton* quickButton=new QPushButton("@",LeftPanel);
QPushButton* focusButton=new QPushButton("F",LeftPanel);
QPushButton* infoButton=new QPushButton("I",LeftPanel);
QPushButton* zoomButton=new QPushButton("Z",LeftPanel);
QPushButton* firstButton=new QPushButton("H",LeftPanel);
QPushButton* lastButton=new QPushButton("E",LeftPanel);
QPushButton* closeButton=new QPushButton("C",LeftPanel);


clustercanvas= new QGLWidget;
clustercanvas->setFixedWidth(325);
clustercanvas->setFixedHeight(150);
panel = new QSplitter(Qt::Horizontal);
panel->addWidget(LeftPanel);
panel->addWidget(hctrl);
panel->addWidget(clustercanvas);


However, the display is like this:
http://www.qtcentre.org/attachment.php?attachmentid=6662&d=1310606806

The width of the left part (marked by red pen) is actually 360 instead of 18.

Why? How can I keep the width of the left part to be 18?

Thanks a lot!

Santosh Reddy
14th July 2011, 03:18
...
panel = new QSplitter(Qt::Horizontal);
panel->addWidget(LeftPanel);
panel->addWidget(hctrl);
panel->addWidget(clustercanvas);

int index = panel.indexOf(LeftPanel);
if(index > -1)
{
QList<int> sizes = panel.sizes();
sizes[index] = 18;
panel.setSizes(sizes);
}

superwave
14th July 2011, 05:20
Hi, thank you very much, I have tried your method, but the result is the same.

Added after 25 minutes:

I followed your idea.

Since the number o button in the panel is not too many, I just set the width of the buttons directly by setfixedwith(16);

Thanks again.

Santosh Reddy
14th July 2011, 05:50
you can also set the size for LeftPanel directly