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):
import sys
from PyQt4 import QtGui, QtCore
def __init__(self, parent = None):
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def mousePressEvent(self, event):
if (event.button() == QtCore.Qt.LeftButton):
self.drag_position = event.globalPos() - self.pos();
event.accept();
def mouseMoveEvent(self, event):
if (event.buttons() == QtCore.Qt.LeftButton):
self.move(event.globalPos().x() - self.drag_position.x(),
event.globalPos().y() - self.drag_position.y());
event.accept();
def initUI(self):
# do some drawing here
if __name__ == '__main__':
window = MyWindow()
#window.initUI()
window.show()
sys.exit(app.exec_())
import sys
from PyQt4 import QtGui, QtCore
class MyWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
def mousePressEvent(self, event):
if (event.button() == QtCore.Qt.LeftButton):
self.drag_position = event.globalPos() - self.pos();
event.accept();
def mouseMoveEvent(self, event):
if (event.buttons() == QtCore.Qt.LeftButton):
self.move(event.globalPos().x() - self.drag_position.x(),
event.globalPos().y() - self.drag_position.y());
event.accept();
def initUI(self):
# do some drawing here
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MyWindow()
#window.initUI()
window.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks