网上全屏窗体拖动的教程很多,但是没有一个说,使用全屏拖动后控件会受到影响,比如使用combobox控件
#!/usr/bin/python
# -*-coding:utf-8-*-
from PyQt5.QtGui import *
from PyQt5.Qt import *
from PyQt5.QtCore import *
class AboutUsDialog(QDialog):
def __init__(self, parent=None):
super(AboutUsDialog, self).__init__(parent)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
self.setGeometry(120, 0, 120, 80)
self.co = QComboBox(self)
self.co.addItems(["test21","testf"])
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
QApplication.postEvent(self, QEvent(174))
event.accept()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
self.move(event.globalPos() - self.dragPosition)
event.accept()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
aboutus = AboutUsDialog()
aboutus.show()
sys.exit(app.exec_())
下面是一个窗口拖动的例子,加了comboboxr控件后,运行当点击combobox会闪退或者窗口会闪到别的位置去,这种不好解决