~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/ThirdParty/chartables/chartables_lib/combobox.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Qt4 combobox utility classes"""
 
2
 
 
3
 
 
4
from PyQt4 import QtCore, QtGui 
 
5
 
 
6
#****************************************************************************
 
7
#
 
8
#****************************************************************************
 
9
class ComboBoxWithEditTipWrap(QtCore.QObject):
 
10
    """Wrapper class for comboboxes to show a tooltip if the text of the editbox
 
11
    is truncated"""
 
12
 
 
13
    def __init__(self, comboBox):
 
14
        QtCore.QObject.__init__(self, comboBox)
 
15
 
 
16
        self.connect(
 
17
            comboBox,
 
18
            QtCore.SIGNAL('currentIndexChanged(const QString &)'),
 
19
            self._adjustToolTip
 
20
            )
 
21
 
 
22
        comboBox.installEventFilter(self)
 
23
        self.comboBox = comboBox
 
24
                
 
25
        
 
26
    def eventFilter(self, obj, event):
 
27
        if event.type() == event.Resize:
 
28
            self._adjustToolTip(self.comboBox.currentText())
 
29
        return False
 
30
        
 
31
        
 
32
    def _adjustToolTip(self, text):
 
33
        fm = self.comboBox.fontMetrics()
 
34
        style = self.comboBox.style()
 
35
        rc = self.comboBox.contentsRect()
 
36
        rc2 = style.subControlRect(
 
37
            style.CC_ComboBox,
 
38
            QtGui.QStyleOptionComboBox(),
 
39
            style.SC_ComboBoxEditField,
 
40
            )
 
41
 
 
42
        cx = rc.width() + rc2.width()
 
43
        w = fm.width(text)
 
44
        if w > cx -2:
 
45
            self.comboBox.setToolTip(text)
 
46
        else:
 
47
            self.comboBox.setToolTip('')