change cursor in pyqt5

Solutions on MaxInterview for change cursor in pyqt5 by the best coders in the world

showing results for - "change cursor in pyqt5"
Damon
23 Oct 2020
1# simply use
2your_widget.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) # set cursor to hand
3# for other cursors look to the link below
4'''
5https://doc.qt.io/qt-5/qcursor.html#a-note-for-x11-users
6'''
7# Example :
8import sys
9from PyQt5 import QtCore, QtGui
10from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
11
12app = QApplication(sys.argv)
13
14window = QWidget()
15window.setGeometry(300, 300, 400, 200)
16window.show()
17
18v = QVBoxLayout()
19l1 = QLabel("This label now has pointing hand cursor")
20l2 = QLabel("but this label has default cursor")
21l1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) # set cursor to pointing hand
22
23v.addWidget(l1)
24v.addWidget(l2)
25window.setLayout(v)
26
27app.exec_()
Alberto
09 Oct 2019
1# simply use
2your_widget.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
3
4# Example :
5import sys
6from PyQt5 import QtCore, QtGui
7from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
8
9app = QApplication(sys.argv)
10
11window = QWidget()
12window.setGeometry(300, 300, 400, 200)
13window.show()
14
15v = QVBoxLayout()
16l1 = QLabel("This label now has pointing hand cursor")
17l2 = QLabel("but this label has default cursor")
18l1.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) # set cursor to pointing hand
19
20v.addWidget(l1)
21v.addWidget(l2)
22window.setLayout(v)
23
24app.exec_()