1
"""Qt4 combobox utility classes"""
4
from PyQt4 import QtCore, QtGui
6
#****************************************************************************
8
#****************************************************************************
9
class ComboBoxWithEditTipWrap(QtCore.QObject):
10
"""Wrapper class for comboboxes to show a tooltip if the text of the editbox
13
def __init__(self, comboBox):
14
QtCore.QObject.__init__(self, comboBox)
18
QtCore.SIGNAL('currentIndexChanged(const QString &)'),
22
comboBox.installEventFilter(self)
23
self.comboBox = comboBox
26
def eventFilter(self, obj, event):
27
if event.type() == event.Resize:
28
self._adjustToolTip(self.comboBox.currentText())
32
def _adjustToolTip(self, text):
33
fm = self.comboBox.fontMetrics()
34
style = self.comboBox.style()
35
rc = self.comboBox.contentsRect()
36
rc2 = style.subControlRect(
38
QtGui.QStyleOptionComboBox(),
39
style.SC_ComboBoxEditField,
42
cx = rc.width() + rc2.width()
45
self.comboBox.setToolTip(text)
47
self.comboBox.setToolTip('')