import sys from PyQt5 import QtWidgets from PyQt5.QtGui import QCursor class MyTextEdit(QtWidgets.QTextEdit): def __init__(self,parent=None): super(MyTextEdit,self).__init__(parent) def focusInEvent(self,event): super(MyTextEdit,self).focusInEvent(event) QtWidgets.QToolTip.showText(QCursor.pos(), 'tooltip') class MainFrame(QtWidgets.QWidget): def __init__(self): super(MainFrame,self).__init__() self.initUI() def initUI(self): self.te=MyTextEdit() hlayout=QtWidgets.QHBoxLayout() hlayout.addWidget(self.te) hlayout.addStretch() self.setLayout(hlayout) self.show() class MainWindow(QtWidgets.QMainWindow): def __init__(self): super(MainWindow,self).__init__() self.main_frame=MainFrame() self.setCentralWidget(self.main_frame) self.setGeometry(100,100,800,600) self.show() if __name__=='__main__': app=QtWidgets.QApplication(sys.argv) mainwindow=MainWindow() sys.exit(app.exec_())