Pyside2 PushButton에 마우스 커서를 올리면 반응하게 할려면 어떻에 해야 되나요?
조회수 566회
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
참고하세요.
import sys from PySide2 import QtCore from PySide2.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QMessageBox class MyForm(QWidget): def __init__(self,parent=None): QWidget.__init__(self,parent) self.setWindowTitle('Button Demo') self.button = QPushButton('Ok',self) self.button.clicked.connect(self.do_clicked) self.button.installEventFilter(self) mainlayout = QVBoxLayout() mainlayout.addWidget(self.button) self.setLayout(mainlayout) def eventFilter(self, obj, event): if obj == self.button and event.type() == QtCore.QEvent.HoverEnter: self.button.setText("Ko") elif obj == self.button and event.type() == QtCore.QEvent.HoverLeave: self.button.setText("Ok") return super(MyForm, self).eventFilter(obj, event) def do_clicked(self): buttonReply = QMessageBox.question(self, 'title', "message", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if buttonReply == QMessageBox.Yes: print('Yes clicked.') else: print('No clicked.') if __name__ == '__main__': app = QApplication(sys.argv) form = MyForm() form.show() app.exec_()
댓글 입력