These two days in summing up some of the previous problems encountered in project, just do not have a colleague asked me about Qt in the various widget window position is how to define, here is summed up:
In Qt, all problems are divided into two different situations: one is the most commonly used qwidget system, and the other is the Qgraphicswidget system.
①: In the commonly used qwidget system, the position before and after setting is mainly raise (), Understack (), hide () function.
Theory: in qt each widget window maintains its own creation stack (widget's stack), where the stack contains an identifier for all of the window's Child widget Windows (representing its various sub-widgets). When a child widget is created, the system will press the identifier on its behalf into the creation stack of its parent widget. and the various sub-widgets displayed before and after the order is: the top of the stack, bottom of the stack. So: the back of the stack is displayed on the top, first into the stack at the bottom. See: The sub-widgets created later are displayed!
Well: When we create multiple sub-widgets with overlapping, the last one we created is definitely the one we saw.
So how do you change that order? For a child widget, we can call the raise () function directly to the top of the stack to display it in front of the topmost user without being obscured; Of course we can also use Understack () to put it under a widget to specify the order.
According to experience, in fact, as long as the use of the Raise () function is sufficient, need to show who, directly let it call raise () can!!
②: For Qgraphicswidget Systems:
Each item is placed internally, and for them: we can directly use Setzvalue () to set the front and back position between each item.
Of course: There is also a mixture, that is, a qgraphicsscene, which can either use AddItem () to add item, or AddWidget () to join the Qwidget object. How do you define the back and forth position between the existing item and the Qwidget?
In fact, when we use AddWidget () to think of adding qwidget to a scene: The function has a return value of qgraphicsproxywidget* type pointer. That is: when we call AddWidget () This function, it does a total of two steps:
A: The system first converts your original Qwidget object to "Item Object".
Second: The converted item is then placed in scene scenes.
But the first step in the conversion of the generated "item object" and the real item object is still not the same, the conversion generated is just a proxy form of the real item! That is: generated a qgraphicsproxywidget type of agent item!! But for this agent item, we can also use Setzvalue () to set its front and back position!
Summed up is that: in a mixed case, when we add a normal qwidget to a scene scene with AddWidget (), we return a qgraphicsproxywidget* type pointer (which represents the agent item that actually put it in the scene), We can use it to call Setzvalue () to set the front and back position, so that it and the normal item of the position of the front and back of the same way!!
http://blog.csdn.net/nrc_douningbo/article/details/5568763
Pre-and post-position settings for each widget in Qt (in Qt, all problems are split, qwidget system and Qgraphicswidget system)