Hallo everyone,
I'm a noob for QT and I'm trying to develop a program for my research work.

I'm trying to produce a QLabel with a transparent background and a transparent mask, in order to be able to click "through" the background of the label and see what happens.
I managed to set a transparent mask for a label but then its background is not updated, so if something happens below the label I do not see it happening.

Please, help! ?(

Here is my code:
Qt Code:
  1. #include <QApplication>
  2. #include <QtGui>
  3.  
  4. void delay()
  5. {
  6. QTime dieTime= QTime::currentTime().addSecs(5);
  7. while( QTime::currentTime() < dieTime )
  8. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  9. }
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13. QApplication a(argc, argv);
  14. QMainWindow* window = new QMainWindow;
  15. QPixmap pixmap(40,40);
  16.  
  17. //window->setWindowFlags(Qt::WindowStaysOnTopHint);
  18. pixmap.fill(Qt::transparent);
  19. QPainter p(&pixmap);
  20. p.setPen(Qt::blue);
  21. p.drawLine(5,5, 40, 40);
  22. p.end();
  23. QLabel label;
  24. label.setPixmap(pixmap);
  25. label.setMask(pixmap.mask());
  26. label.setWindowFlags(Qt::WindowStaysOnTopHint);
  27. label.setAttribute(Qt::WA_TranslucentBackground);
  28. // label.setAutoFillBackground(true);
  29. label.show();
  30. //QCursor::setPos(40, 40);
  31. delay();
  32.  
  33. label.move(40,40);
  34. return a.exec();
  35. }
To copy to clipboard, switch view to plain text mode