Hi there, first time poster here. Got a bit of a difficult issue with Qt cross OS. I'm trying to accomplish the following with a Qt (C++) app, cross OS:
Upon running the program a new window pops up, a fullscreen QWidget. Now I want this to be see-through/transparent, so the user won't actually see it. On this 'layer' a user can drag his/her mouse to draw a (red) rectangle to select an area which is - when the mouse is released - taken a screenshot of.

The problem:
The issue lays in the whole transparent layer thing since this doesn't appear to work well cross OS. Because when I click on where the layer is, to invoke the mousePressEvent(), I click through it on to the window below it as if it isn't even there. On Ubuntu, however, I do not. I want the same effect on Windows, but thus far I got nothing...
(Making another GUI object appear, such as button, would only make the button a clickable part of the layer)

Tested on Ubuntu 11.04 32-bit and Windows 7 Home Premium 64-bit. (Trying to get around to a Mac one, would this issue be solved.)

So does anyone know how this would work?
I've included my code thus far. (Clearing out all my 100 other attempts.)

main.cpp
Here I set the translucentBackground, here I probably miss a setting or something is not configured right.
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include "widget.h"
  3. int main(int argc, char *argv[])
  4. {
  5. QApplication a(argc, argv);
  6. Widget w;
  7. //Fullscreen app
  8. w.showFullScreen();
  9. w.setAttribute(Qt::WA_NoSystemBackground);
  10. w.setAttribute(Qt::WA_TranslucentBackground);
  11. w.setMouseTracking(true);
  12. w.setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
  13. //Show
  14. w.show();
  15. return a.exec();
  16. }
To copy to clipboard, switch view to plain text mode 

widget.cpp
Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include "QDebug"
  4. Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
  5. {
  6. this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
  7. QPalette palette(Widget::palette());
  8. palette.setColor(backgroundRole(), Qt::white);
  9. setPalette(palette);
  10. this->clicked = false;
  11. ui->setupUi(this);
  12. }
  13. Widget::~Widget()
  14. {
  15. delete ui;
  16. }
  17. void Widget::mousePressEvent ( QMouseEvent * event )
  18. {
  19. //Record start
  20. if (event->button() == Qt::LeftButton){
  21. x = event->globalX();
  22. y = event->globalY();
  23. this->clicked = true;
  24. width = 0;
  25. height = 0;
  26. }
  27. }
  28. void Widget::mouseMoveEvent ( QMouseEvent * event )
  29. {
  30. if (this->clicked == true){
  31. int x2 = event->globalX();
  32. int y2 = event->globalY();
  33. if(x < x2){
  34. width = x2 - x;
  35. }else{
  36. width = x - x2;
  37. //Resetting startpoint when dragging to the left side on your screen, copy from java so this doesn't actually works yet.
  38. x = x - width-2;
  39. }
  40. if(y < y2){
  41. height = y2 - y;
  42. }else{
  43. height = y - y2;
  44. //Resetting startpoint when dragging to the left side on your screen, copy from java so this doesn't actually works yet.
  45. y = y - height-2;
  46. }
  47. //Redraw rectangle
  48. update();
  49. qDebug("wa");
  50. }
  51. }
  52. void Widget::mouseReleaseEvent ( QMouseEvent * event )
  53. {
  54. if (event->button() == Qt::LeftButton)
  55. {
  56. //Record end
  57. qDebug("-------");
  58. this->clicked = false;
  59. }
  60. }
  61. void Widget::paintEvent(QPaintEvent *)
  62. {
  63. QPainter painter(this);
  64. painter.setRenderHint(QPainter::Antialiasing);
  65. painter.setPen(Qt::red);
  66. painter.drawRect(x,y,width,height);
  67. }
To copy to clipboard, switch view to plain text mode 

widget.h
Qt Code:
  1. #ifndef WIDGET_H
  2. #define WIDGET_H
  3. #include <QWidget>
  4. #include <QtGui>
  5. #include<QMouseEvent>
  6. namespace Ui {
  7. class Widget;
  8. }
  9. class Widget : public QWidget
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit Widget(QWidget *parent = 0);
  14. ~Widget();
  15. private:
  16. Ui::Widget *ui;
  17. bool clicked;
  18. int x,y,width,height;
  19. void mousePressEvent ( QMouseEvent * event );
  20. void mouseMoveEvent ( QMouseEvent * event );
  21. void mouseReleaseEvent ( QMouseEvent * event );
  22. protected:
  23. void paintEvent(QPaintEvent *);
  24. };
  25. #endif // WIDGET_H
To copy to clipboard, switch view to plain text mode 

Also, I think I've gone through every result Google will find on this subject, same as the API docs of Qt. I've seriously run out of options for this one. (I started this project in Java, but C++ with Qt seems to be, thus far, far less work.)

Any help would very much be appreciated!