방금 비슷한 질문을했지만 (미안 해요!) 도움이 더 필요하다고 생각합니다. pyqt의 신호에 문제가 있습니다. ... 그것은 오래는 아니고, 내가 설명하기가 쉽다 나 전체 코드를 게시mousepressevent의 문제점
from PyQt4 import QtGui, QtCore, Qt
import time
import math
class FenixGui(QtGui.QWidget):
def backgroundmousepressevent(self, event):
print "test 1"
self.offset = event.pos()
def backgroundmousemoveevent(self, event):
print "test 2"
x=event.globalX()
y=event.globalY()
x_w = self.offset.x()
y_w = self.offset.y()
self.move(x-x_w, y-y_w)
def __init__(self):
super(FenixGui, self).__init__()
# setting layout type
hboxlayout = QtGui.QHBoxLayout(self)
self.setLayout(hboxlayout)
# hiding title bar
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
# setting window size and position
self.setGeometry(200, 200, 862, 560)
self.setAttribute(Qt.Qt.WA_TranslucentBackground)
self.setAutoFillBackground(False)
# creating background window label
backgroundpixmap = QtGui.QPixmap("fenixbackground.png")
self.background = QtGui.QLabel(self)
self.background.setPixmap(backgroundpixmap)
self.background.setGeometry(0, 0, 862, 560)
# making window draggable by the window label
self.connect(self.background,QtCore.SIGNAL("mousePressEvent()"), self.backgroundmousepressevent)
self.connect(self.background,QtCore.SIGNAL("mouseMoveEvent()"), self.backgroundmousemoveevent)
# fenix logo
logopixmap = QtGui.QPixmap("fenixlogo.png")
self.logo = QtGui.QLabel(self)
self.logo.setPixmap(logopixmap)
self.logo.setGeometry(100, 100, 400, 150)
def main():
app = QtGui.QApplication([])
exm = FenixGui()
exm.show()
app.exec_()
if __name__ == '__main__':
main()
모든 권리를하자, 그래서 이것은 코드입니다, 내가 드래그 확인하고 싶었 단순한 GUI를 백그라운드에서 아무 곳이나 클릭하고 드래그하여 화면 주위. 내 문제는 : backgroundmousepressevent 및 backgroundmousemoveevent 내가 누르거나 단추를 이동할 때 해고하지 마십시오. 그래서 나는 궁금합니다 : 어디서 오류가 있습니까? 나는 무엇인가 또는 무엇을 잘못 알려주 었는가? 고마워요!
Matteo
제발, 기존의 코딩 스타일을 적응하십시오. 나는 "파이썬 코딩 스타일"을 제안 할 것이다. http://www.python.org/dev/peps/pep-0008/ 그러나 PyQt를 많이 사용하는 것처럼 보이기 때문에 아마도 Qt 코딩 스타일이 더 적합 할 것이다. 당신 : http://developer.qt.nokia.com/wiki/Qt_Coding_Style – Constantinius
그는 주로 복사/붙여 넣기에 문제가 있음이 분명합니다. – Profane