简体   繁体   English

Qt:是否允许非矩形 QWidget 重叠?

[英]Qt: Are non-rectangular QWidgets allowed to overlap?

If I have multiple non-rectangular custom QWidget s (eg circle-shaped buttons), can I overlap them?如果我有多个非矩形自定义QWidget (例如圆形按钮),我可以重叠它们吗?

It seems there is no way to let Qt know which parts of the widgets are opaque, so mouse event are delivered to the correct QWidget (It looks like Qt assumes each widget occupies its bounding rectangle).似乎没有办法让 Qt 知道小部件的哪些部分是不透明的,因此鼠标事件被传递给正确的QWidget (看起来 Qt 假设每个小部件都占据其边界矩形)。

Should I turn these widgets into QGraphicsItem s instead?我应该把这些小部件变成QGraphicsItem吗?

You can give QWidgets a mask if you want them to be non-rectangular.如果你希望 QWidgets 是非矩形的,你可以给它们一个遮罩。 This should work, but it's not always straightforward to create the mask region.这应该可行,但创建遮罩区域并不总是那么简单。 QGraphicsItem certainly makes handling non-rectangular shapes much easier. QGraphicsItem 确实使处理非矩形形状变得更加容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM