The only way I found to do this is here: How to make QCheckBox readonly, but not grayed-out. This, however, disables mouse interactions with the control. But I need the tooltip to be displayed when mouse is over the control. How can I achieve this?
Asked
Active
Viewed 1.2k times
0
-
1This seems a horrible thing to do from a ux pov, since it completely undermines the normal behaviour. What's the use-case? – ekhumoro Jul 28 '16 at 18:26
-
If you don't need to have the checkbox not grayed out, you can disable it; the tooltip still displays for a disabled checkbox. I'm not sure how to make it disabled without graying it out – Peter Wang Jul 29 '16 at 18:08
-
There's an option that I control somewhere else that I don't want to look gray. That's all. @PeterWang – The Quantum Physicist Jul 29 '16 at 22:49
-
There's an option that I control somewhere else that I don't want to look gray. That's all. @ekhumoro – The Quantum Physicist Jul 29 '16 at 22:49
2 Answers
3
If I've understood correctly, this is what you'd be asking for, a disabled checkbox showing tooltips:
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()

BPL
- 9,632
- 9
- 59
- 117
-
You missed the part "not grayed out"... I want it disabled without being gray. – The Quantum Physicist Aug 03 '16 at 20:12
-
@TheQuantumPhysicist Ok, I've missed that part indeed. I've edited my answer, that way you'd have it "not grayed out" – BPL Aug 03 '16 at 20:39
-
-
-
-
@TheQuantumPhysicist Ok, I've edited my answer again, this time should satisfy all your requirements – BPL Aug 09 '16 at 12:28
-
@BPL - Can you explain how this works? It took me a bit to realize what you were doing and I suspect the viewers at home might not get it right away either... – chmedly Jun 22 '20 at 04:21
2
#If your are not expecting this answer, sorry.
self.checkBox = QtGui.QCheckBox()
self.checkBox.setEnabled (False)
self.checkBox.setToolTip ('my checkBox')

Subin Gopi
- 541
- 2
- 12
-
Sorry. This is so not what I want. I definitely know disabled, and that's why I asked for "not grayed out". – The Quantum Physicist Jul 29 '16 at 22:50