Search code examples
c++qtdrawingqpainter

Generic transparent Qt widget that can catch clicks?


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 accomplish 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?


Solution

  • 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.