PDA

View Full Version : QToolBox + resize + hide



eleanor
23rd October 2007, 20:16
Hi, this is my code now:



m_pToolbox = new QToolBox();
Q_CHECK_PTR(m_pToolbox);


m_pTabSifrant = new QTabWidget();
Q_CHECK_PTR(m_pTabSifrant);
m_pTabVnos = new QTabWidget();
Q_CHECK_PTR(m_pTabVnos);
m_pTabIsci = new QTabWidget();
Q_CHECK_PTR(m_pTabIsci);
m_pTabNatisni = new QTabWidget();
Q_CHECK_PTR(m_pTabNatisni);

//tabs
m_pToolbox->addItem(m_pTabSifrant,trUtf8("Šifranti"));
m_pToolbox->addItem(m_pTabVnos,trUtf8("Vnos"));
m_pToolbox->addItem(m_pTabIsci,trUtf8("Iskanje"));
m_pToolbox->addItem(m_pTabNatisni,trUtf8("Tiskanje"));

//add QToolBox to the main widget
m_pMainLayout->addWidget(m_pToolbox);
//set stretch factor to 1
m_pMainLayout->setStretchFactor(m_pToolbox,1);

//add blank widget to main widget --> we'll have to change that to insert a widget we'll use. This is just for testing purposes
QWidget *test = new QWidget();
m_pMainLayout->addWidget(test);
m_pMainLayout->setStretchFactor(test,3);




Now I want a way to resize and hide the QToolBox, like in kpdf program. There's a little sidebar (where the slides are in minimal form) and you can resize it and hide it. When it's hidden you can also drag it on the right again to show it..


How can I do that.

eleanor
24th October 2007, 10:35
Let me show you how this should look like:

http://shrani.si/f/1p/jk/2y1hlJY8/snapshot28.png
http://shrani.si/f/1v/k8/1TpGl9Qs/snapshot29.png

jpn
24th October 2007, 11:06
Take a look at QSplitter.

eleanor
24th October 2007, 12:22
Hi. That was a good tip man:



splitter = new QSplitter();
Q_CHECK_PTR(splitter);

//tabs
m_pToolbox->addItem(m_pTabSifrant,trUtf8("Šifranti"));
m_pToolbox->addItem(m_pTabVnos,trUtf8("Vnos"));
m_pToolbox->addItem(m_pTabIsci,trUtf8("Iskanje"));
m_pToolbox->addItem(m_pTabNatisni,trUtf8("Tiskanje"));

//add QToolBox to the splitter widget
splitter->insertWidget(0,m_pToolbox);

//add blank widget to splitter widget --> we'll have to change that to insert a widget we'll use. This is just for testing purposes
QWidget *test = new QWidget();
splitter->insertWidget(1,test);

//sets whether the child at index is collapsible to collapse
splitter->setCollapsible(0,true);
splitter->setCollapsible(1,false);
//set's the stretch factor to specific widget
splitter->setStretchFactor(0,1);
splitter->setStretchFactor(1,3);

//sets the size of the 2 widgets in QSplitter
QList<int> m_SizeList;
m_SizeList << 100 << 500;
splitter->setSizes(m_SizeList);


//add QSplitter to the main widget
m_pMainLayout->addWidget(splitter);


Now the only thing I want to do is to let the QToolBox resize only 1/3 of the screen (that would be the maximum width for that widget). I've looked everywhere to find function for that, but I couldn't find it. Any tips?

eleanor
24th October 2007, 14:22
When QToolBOx is hidden, it now looks like this:

http://linux.prinas.si/galerija/albums/userpics/10201/thumb_snapshot30.png (http://linux.prinas.si/galerija/displayimage.php?pos=-687)

and I want it to look like this:


http://linux.prinas.si/galerija/albums/userpics/10201/thumb_snapshot31.png (http://linux.prinas.si/galerija/displayimage.php?pos=-686)

high_flyer
24th October 2007, 14:36
Now the only thing I want to do is to let the QToolBox resize only 1/3 of the screen (that would be the maximum width for that widget). I've looked everywhere to find function for that, but I couldn't find it. Any tips?
you could overload resizeEvent().


When QToolBOx is hidden, it now looks like this:
in the second image we see the inner edge of a main window - but what do we see in the first?

eleanor
24th October 2007, 14:57
In the first image you see the closed QToolBox as you do in the second image (if you grab it and go right, the QToolBox openes...)

I just want this closed QToolBox to be on the left corner of the main widget (like in second picture) and not a few inches to the right.

high_flyer
24th October 2007, 15:49
I just tried it, and i get no such left margins...
are you sure you placed the whole splitter layout on the inner edge of the main widget?

eleanor
24th October 2007, 16:10
Can you post your code somewhere so I can test if your's are displays by the left cornet correctly...

Thanks

high_flyer
24th October 2007, 16:20
oh, I know now what you mean.
What you see, is the splitter "handle".
You can adjust its width with setHandleWidth () or in designer in the property editor.

the open image is with handle width 5 and the closed with width 2.

eleanor
24th October 2007, 16:32
No no, I mean I want to get rid of the space between MainWindow frame and handle.

high_flyer
24th October 2007, 16:53
but as you can see in the images, there is no space between the MainWindow frame and the handle.

eleanor
24th October 2007, 17:14
In your case yes, but the first picture of mine there is space...and I don't have any other widgets there.

eleanor
24th October 2007, 19:12
Ok, I'll survive without this. But have another question:

How can I save the size the user set. Let's say the user run the program for the first time and then he want's to have the same size of the QToolBox every time he run's the program again. How to do that?

jpn
24th October 2007, 19:41
Use QSplitter::saveState() and QSplitter::restoreState() together with QSettings. Notice examples in docs.