spacepaste

  1.  
  2. import sys
  3. from PyQt5 import QtWidgets
  4. from PyQt5.QtGui import QCursor
  5. class MyTextEdit(QtWidgets.QTextEdit):
  6. def __init__(self,parent=None):
  7. super(MyTextEdit,self).__init__(parent)
  8. def focusInEvent(self,event):
  9. super(MyTextEdit,self).focusInEvent(event)
  10. QtWidgets.QToolTip.showText(QCursor.pos(), 'tooltip')
  11. class MainFrame(QtWidgets.QWidget):
  12. def __init__(self):
  13. super(MainFrame,self).__init__()
  14. self.initUI()
  15. def initUI(self):
  16. self.te=MyTextEdit()
  17. hlayout=QtWidgets.QHBoxLayout()
  18. hlayout.addWidget(self.te)
  19. hlayout.addStretch()
  20. self.setLayout(hlayout)
  21. self.show()
  22. class MainWindow(QtWidgets.QMainWindow):
  23. def __init__(self):
  24. super(MainWindow,self).__init__()
  25. self.main_frame=MainFrame()
  26. self.setCentralWidget(self.main_frame)
  27. self.setGeometry(100,100,800,600)
  28. self.show()
  29. if __name__=='__main__':
  30. app=QtWidgets.QApplication(sys.argv)
  31. mainwindow=MainWindow()
  32. sys.exit(app.exec_())
  33.