赞
踩
具体设为手型的代码
self.button.setCursor(QCursor(Qt.PointingHandCursor))
具体的测试代码如下:
- import sys
- from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
- from PyQt5.QtGui import QCursor
- from PyQt5.QtCore import Qt
-
-
- class Example(QWidget):
-
- def __init__(self):
- super().__init__()
-
- self.initUI() # 界面绘制交给InitUi方法
-
- def initUI(self):
- # 设置窗口的位置和大小
- self.setGeometry(300, 300, 300, 220)
- # 设置窗口的标题
- self.setWindowTitle('QPushButton')
-
- #控件QPushButton的定义和设置
- self.button = QPushButton('手型', self)
- self.button.setGeometry(100, 100, 50, 50)
- self.button.setCursor(QCursor(Qt.PointingHandCursor))
-
-
- if __name__ == '__main__':
- # 创建应用程序和对象
- app = QApplication(sys.argv)
- ex = Example()
- ex.show()
- sys.exit(app.exec_())

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。