Python 3:PyQt:禁用复选框+不灰显+显示工具提示

Python 3: PyQt: Make checkbox disabled + not grayed out + display tooltip

我找到的唯一方法是 。但是,这会禁用鼠标与控件的交互。但是我需要在鼠标悬停在控件上时显示工具提示。我怎样才能做到这一点?

#If your are not expecting this answer, sorry.

self.checkBox = QtGui.QCheckBox()
self.checkBox.setEnabled (False)
self.checkBox.setToolTip ('my checkBox')

如果我没理解错的话,这就是您想要的,一个显示工具提示的禁用复选框:

 import sys
 from PyQt4 import QtGui, QtCore


 class Example(QtGui.QWidget):

      def __init__(self):
           super(Example, self).__init__()
           self.initUI()

      def initUI(self):
           self.cb = QtGui.QCheckBox('Disabled CheckBox showing tooltips', self)
           self.cb.move(20, 20)
           self.cb.toggle()
           # self.cb.setEnabled(False)
           # self.cb.setStyleSheet("color: black")
           # self.cb.setAttribute(QtCore.Qt.WA_AlwaysShowToolTips)
           self.cb.setToolTip ('my checkBox')
           self.cb.toggled.connect(self.prevent_toggle)

           self.setGeometry(300, 300, 250, 50)
           self.setWindowTitle('QtGui.QCheckBox')
           self.show()

      def prevent_toggle(self):
           self.cb.setChecked(QtCore.Qt.Checked)

 def main():
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())


 if __name__ == '__main__':
      main()