PDA

View Full Version : Controlling which widget on top layer?



JonathanForQT4
22nd March 2007, 11:47
Hello all, as of right now my program has a main widget, which has lots of child widgets. These child widgets are painted onto the mainwidget and are transparent; so whenever the main widget gets a paintEvent the childwidgets also receive a paintEvent.

My question is as follows: some of these child widgets overlap and I need to be able to let the user select which widget gets painted on top of the others (so one widget is in the foreground) because this top widget needs to be able to receive mouseEvents...and if a widget is not on top and is covered by another widget it will not get these mouse events...thus I need to know how to change the paint/layer order.

Any help would be appreciated.

:D

Jonathan

jpn
22nd March 2007, 11:48
QWidget::raise()
QWidget::lower()

JonathanForQT4
22nd March 2007, 11:52
dude, awesome --- thank you for this.

JonathanForQT4
22nd March 2007, 11:56
while I'm here, I guess I could ask my second question...there are quite a few of these child widgets....sometimes the count is larger than 10 thousand....since they all receive a paintEvent when the parent gets one (each time the mouse is moved..etc.) it bogs the program down so much that it can't display anything anymore.

Is there a work around for this? I have tried using setUpdatesEnabled but when it is used for the children widgets...nothing gets painted as soon as the parent gets a paintEvent...

Thanks again,

Jonathan

jpn
22nd March 2007, 12:06
there are quite a few of these child widgets....sometimes the count is larger than 10 thousand....since they all receive a paintEvent when the parent gets one (each time the mouse is moved..etc.) it bogs the program down so much that it can't display anything anymore.
That's huge amount of widgets. I wouldn't suggest using so many widgets because excessive amount of child widgets tend to eat resources quite a bit as you have noticed already. Could you provide a screenshot of how the GUI looks like? Maybe there could be other possibilities like model/view (http://doc.trolltech.com/4.2/model-view-programming.html) or graphicsview (http://doc.trolltech.com/4.2/graphicsview.html) frameworks.

JonathanForQT4
22nd March 2007, 13:36
well....I can't provide a screenshot, but I can say the following: all you'd see is a main window with a scroll area with the scroll area's centralwidget being the mainWidget I described above. The main widget has all different types of children widgets. They are either rectangles or circles. There about about 7 types of these child widgets, but as I understand it, with the graphicsview route a type (of the 7) would be added to a graphics scene and then the scene would be painted to the mainWidget. The problem is, within one type of child widget I need to be able to to tell the difference.....because of one type of child widget, there could be a couple of thousand instances of it (which I need to be able to distinguish).
So that begs the question: I would have to make a graphics scene for each element from each of the 7 types and then print them to the mainWidget. Would I be bogged down with memory issues like before? It seems that I can receive mouseEvents with graphics scenes so that would suffice :)

As for the model/view programming, I have read the documentation, but fail to see how it would be of use in my case...but I'm sure that I've overlooked the underlying idea you are pointing to (because I'm a noob with qt)....maybe you could go more in to depth with an overview/example?

JonathanForQT4
22nd March 2007, 14:27
actually nevermind...you could add seperate items to a scene since not only qgraphics scene gets mouseEvents, but also the items....so I should be able to do it on one scene....time to try it out I guess :)

thanks again,

Jonathan