Hello,

I have a program consisting of many drawn rectangles on a QMainWindow with FramelessWindowHint. To still be able to move the window I overrode mouseMove- and mousePressEvent. Next I made the window transparent and as a result could only move it with the mouse over one of the rectangles. What I want is to be able to move it when the mouse is over the (transparent!) MainWindow. Should I use another method to make it transparent or is there any way I can make it respond to my mouseEvents?

Here's a simplified example code (I'm using PyQt 4.7 with Python 2.6.6 on Windows 7):
Qt Code:
  1. import sys
  2. from PyQt4 import QtGui, QtCore
  3.  
  4. class MyWindow(QtGui.QMainWindow):
  5.  
  6. def __init__(self, parent = None):
  7. QtGui.QMainWindow.__init__(self, parent)
  8. self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  9. #self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
  10.  
  11. def mousePressEvent(self, event):
  12. if (event.button() == QtCore.Qt.LeftButton):
  13. self.drag_position = event.globalPos() - self.pos();
  14. event.accept();
  15.  
  16. def mouseMoveEvent(self, event):
  17. if (event.buttons() == QtCore.Qt.LeftButton):
  18. self.move(event.globalPos().x() - self.drag_position.x(),
  19. event.globalPos().y() - self.drag_position.y());
  20. event.accept();
  21.  
  22. def initUI(self):
  23. # do some drawing here
  24.  
  25. if __name__ == '__main__':
  26. app = QtGui.QApplication(sys.argv)
  27.  
  28. window = MyWindow()
  29. #window.initUI()
  30. window.show()
  31.  
  32. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode