Qt - What is meant by this sentence

蓝咒 提交于 2019-12-11 06:05:36

问题


At the following web page: http://web.mit.edu/qt-dynamic/www/tutorials-tutorial-t3.html

The following sentence is mentioned:

A widget is clipped by its parent and by the widgets in front of it.

What do we mean by such sentence?

Thanks.


回答1:


Qt has the concept of parent/child widgets. The parent widget is the container of the child widget, all the way up to the main window widget. So this is just saying that a widget will be clipped by its parent (container) widget. This means it won't extend past its parent's boundaries, but will be cut off if it goes beyond. Likewise, a widget is clipped by any widgets in front of it.




回答2:


First off: the second part of the sentence is no longer true for Qt >= 4.1 where a parent may paint behind its children.

In graphics, clipping describes the limiting of the painting to a given area. E.g. if you drew a line from (0,0) to (100,100) with a clipping rectangle of (50x50)@(0,0), you'd effectively draw a line only from (0,0) to (50,50), ie. all pixels that would have been painted, but lay outside the clipping region, were discarded.

In Qt, painting can optionally be clipped using QPainter methods, but the painting is always implicitly clipped by the QPaintDevice you're operating on. QWidget is a QPaintDevice, and as such, painting outside of its QWidget::rect() will have no effect (= it will be clipped to rect()).

Now, about the second part of the sentence: In older Qt versions, the child widgets would first fill their area with the background color/image, thus effectively clipping the parent's painting to outside the union of all children's geometries. Since Qt 4.1, this behaviour can be disabled by setting the QWidget::autoFillBackground property to false. Indeed, this happens to be the new default, too.

In the autoFillBackground == false case, the child widgets do no longer erase the parent's drawing acting as their background, except where they actually paint. Take a QLabel as an example: with autoFillBackground == false, it merely paints its text, leaving the parent's drawing to shine through as the label's background.



来源:https://stackoverflow.com/questions/5793903/qt-what-is-meant-by-this-sentence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!