PDA

View Full Version : Can you change which widgets are drawn on top?



Spectralist
4th December 2009, 22:41
I have an array of QWidgets created throughout the life of my application and the newest ones are always rendered on top of the oldest. I sometimes need to pull an old one on top. Is there some way to change the order that the widgets are drawn in?

rainspider
5th December 2009, 15:53
try to create and show a same button(name of btnChangeState )in each widget,and connect all this button's click signal to one slot(name of ChangeState).In the ChangeState method,you can show a popupmenu.items of the menu is a list of your all widgets.user can select one widget on top by click menu.

show a select-widget on top :
1.hide old-top-widget and selected-widget;
2.show old-top-widget
3.show selected-widget

note:There can be only one widget is on top at the same time .

Spectralist
5th December 2009, 21:58
That's not working for me. I create some widgets with something similar to this:


QWidget * main;
main = new QWidget;
QList<QWidget *> test;

for(int n = 0; n < 10; n++)
{
QWidget * tempW;
tempW = new QWidget(main);

tempW->show();
tempW->move(0, n*70);
test.append(tempW);
}

Then in another portion of code I reorganize the widgets and the QList and after that their default draw order is no longer appropriate. Now if I'm understanding you correctly this:


for(int n = 0; n < test.count(); n++)
test[n]->hide();

for(int n = 0; n < test.count(); n++)
test[n]->show();

should order them so that the later indexed widgets draw on top of the earlier indexed widgets. But that's not happening. They continue to draw according to the order they were "new"ed in.

nish
6th December 2009, 04:36
you need to call a function QWidget::raise() it will bring that widget to the top of stack

Spectralist
6th December 2009, 18:31
Thanks! I went through the public functions list 5 or 6 times looking for a function that does this but somehow didn't think to look under the slots category. :o