开发者

Generic transparent Qt widget that can catch clicks?

开发者 https://www.devze.com 2023-01-01 07:54 出处:网络
I\'ve figured out how to use QPainter to draw rectangles. Now I want to have a drawing area where if the user clicks, a 1x1 rectangle is drawn where the mouse pointer is. To a开发者_如何学编程ccomplis

I've figured out how to use QPainter to draw rectangles. Now I want to have a drawing area where if the user clicks, a 1x1 rectangle is drawn where the mouse pointer is. To a开发者_如何学编程ccomplish this, I assume I need a transparent Qt widget that supports the clicked() signal.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消