简体   繁体   English

可以捕获点击的通用透明Qt小部件?

[英]Generic transparent Qt widget that can catch clicks?

I've figured out how to use QPainter to draw rectangles. 我已经弄清楚了如何使用QPainter绘制矩形。 Now I want to have a drawing area where if the user clicks, a 1x1 rectangle is drawn where the mouse pointer is. 现在,我想要一个绘图区域,如果用户单击该区域,将在鼠标指针所在的位置绘制一个1x1的矩形。 To accomplish this, I assume I need a transparent Qt widget that supports the clicked() signal. 为此,我假设我需要一个支持clicked()信号的透明Qt小部件。

How do I make such a transparent widget? 如何制作透明的小部件? Or is there something else I can use? 还是我还有其他可以使用的东西? Perhaps I can only use the window's clicked() signal? 也许我只能使用窗口的clicked()信号?

You don't really need a transparent widget? 您真的不需要透明的小部件吗?

All you have to do is implement 您要做的就是实施

protected:
  void mousePressEvent(QMouseEvent *event);

for your widget and draw your rectangle. 为您的小部件绘制矩形。

Take a look at scribble example that comes with Qt. 看一下Qt附带的涂鸦示例

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

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