So currently in my GUI, I have many fields that need some explanation of what they do. I was wondering if there was a way to have a small window or secion popup if the user hovers the mouse over a certain kind of widget?
So I have this code:
class mainWindow(QtGui.QWidget):
def __init__(self):
super(mainWindow, self).__init__()
self.layout = QtGui.QVBoxLayout()
self.label1 = QtGui.QLabel()
self.label1.setText("Name")
self.lineEdit1 = QtGui.QLineEdit()
self.label2 = QtGui.QLabel()
self.label2.setText("Age")
self.lineEdit2 = QtGui.QLineEdit()
I would like a small popup window to show when I hover over self.lineEdit1
and self.lineEdit2
with different messages. Is there a way to do so?
The simplest and standard way is to use a tooltip. Every widget in Qt has a toolTip property you can use
class mainWindow(QtGui.QWidget):
def __init__(self):
super(mainWindow, self).__init__()
self.layout = QtGui.QVBoxLayout()
self.label1 = QtGui.QLabel()
self.label1.setText("Name")
self.lineEdit1 = QtGui.QLineEdit()
self.lineEdit1.setToolTip("This is a ToolTip")
self.label2 = QtGui.QLabel()
self.label2.setText("Age")
self.lineEdit2 = QtGui.QLineEdit()
self.lineEdit2.setToolTip("This is another ToolTip")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.