在 Qt Designer 中分层 UI 元素
我有一个 QLabel,我不断地设置它的像素图(视频播放)。在我的应用程序中,用户需要能够在视频上方绘制(框)。如何将 QPaintDevice 类(QWidget、QPixmap、QImage 等)之一直接放在上面并与用于绘画的 QLabel 具有相同的大小。该元素需要具有透明背景,以便在其上绘制的形状将出现在视频上。
I have a QLabel that I'm constantly setting it's pixmap (video playback). In my application the user needs to be able to draw (boxes) above the video. How can I layer one of the QPaintDevice classes (QWidget, QPixmap, QImage, etc.) directly above and with the same size as the QLabel for painting. This element will need to have a transparent background so shapes drawn on it will appear over the video.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加要在其上绘制形状的小部件作为视频标签的子小部件。首先添加布局,以便子窗口小部件将与父窗口小部件的大小相匹配。代码将是这样的:
您应该看到文本覆盖在视频上,并且如果调整大小,它应该保持在视频小部件的中心。对于您的最终代码,您将使用您自己的一些小部件子类,它允许您拦截鼠标操作并绘制矩形,但这是基本思想。
Add the widget you want to draw shapes on as a child widget of the video label. Add a layout first so the child widget will match the size of the parent widget. The code would be something like this:
You should see the text overlaid on the video and it should remain centered over the video widget if it is resized. For your final code, you would use some widget subclass of your own that allowed you to intercept mouse actions and draw rectangles but that's the basic idea.