Set the front and back positions of widgets in QT)

Source: Internet
Author: User

In the past two days, I have summarized some problems encountered in the project. Some colleagues in other groups asked me how to define the front and back positions of various widget windows in QT. Here I will summarize:

In QT, all the questions should be divided into two parts to discuss two different situations: one is the most common qwidget system, and the other is the qgraphicswidget system.

 

①: In the common qwidget system, the preceding and following positions are mainly set using raise (), understack (), and hide () functions.

In theory, every widget window in QT maintains its own creation stack (widget's stack .), the stack stores the identifiers of all child widgets in the window (representing each child widget ). After a child widget is created, the system pushes its identifier to the creation stack of its parent widget. The sub-widgets display the following sequence: top of the stack and bottom of the stack. So: After the stack is pushed to the top, the first stack is pushed to the bottom. We can see that the created child widget is displayed!

So: After we create multiple child widgets with overlapping widgets, the last created child widgets must be the one we see.

How can we change this order? For a sub-widget, we can directly call the raise () function to raise it to the top of the stack, so as to display it in front of the top user without being blocked; of course, we can also use understack () to place it under a sub-widget to specify the forward and backward order.

 

Based on experience, you only need to use the raise () function. You can directly call raise () to identify the target user !!

 

②: For the qgraphicswidget system:

Each item is placed inside it. For them, we can directly use setzvalue () to set the front and back positions between items.

 

 

Of course, there is also a hybrid situation, that is, a qgraphicsscene, where you can use additem () to add items, or addwidget () to add qwidget objects. How can we define the positions between items and qwidgets?

 

In fact, when we use addwidget () to add qwidget to scene: this function has a return value, which is a qgraphicsproxywidget * type pointer. That is, when we call the addwidget () function, we perform two steps:

1. the system first converts your original qwidget object to an "item object ".

Ii. Put the converted item into the scene scenario.

However, in the first step, the "item object" generated by the conversion is different from the real item object. The conversion generates only a proxy form of the real item! That is, a qgraphicsproxywidget proxy item is generated !! But for this proxy item, we can also use setzvalue () to set its front and back positions!

 

To sum up, when we use addwidget () to add a common qwidget to a scene scenario, A qgraphicsproxywidget * type pointer is returned (which indicates the proxy item that is actually put into this scene). We can use it to call setzvalue () to set the front and back positions, in this way, it is consistent with the setting method of the front and back positions of common items !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.