Use a dynamic size for list of buffers and nicklist (based on longer text)

This commit is contained in:
Sebastien Helleu 2011-12-08 10:42:06 +00:00
parent 6b52019908
commit dc15599ca2

View File

@ -30,30 +30,31 @@ from chat import ChatTextEdit
from input import InputLineEdit from input import InputLineEdit
class BufferListWidget(QtGui.QListWidget): class GenericListWidget(QtGui.QListWidget):
"""Widget with list of buffers.""" """Generic QListWidget with dynamic size."""
def __init__(self, *args): def __init__(self, *args):
apply(QtGui.QListWidget.__init__, (self,) + args) apply(QtGui.QListWidget.__init__, (self,) + args)
self.setMaximumWidth(100)
self.setTextElideMode(QtCore.Qt.ElideNone)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setMinimumWidth(120)
self.setMaximumWidth(200)
# TODO: do a dynamic size for widget
#self.setMinimumWidth(self.sizeHintForColumn(0))
#self.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding)
#self.setResizeMode(QtGui.QListView.Adjust)
self.setFocusPolicy(QtCore.Qt.NoFocus) self.setFocusPolicy(QtCore.Qt.NoFocus)
pal = self.palette() pal = self.palette()
pal.setColor(QtGui.QPalette.Highlight, QtGui.QColor('#ddddff')) pal.setColor(QtGui.QPalette.Highlight, QtGui.QColor('#ddddff'))
pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('black')) pal.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('black'))
self.setPalette(pal) self.setPalette(pal)
# TODO: do a dynamic size for widget def addItem(self, *args):
def sizeHint(self): """Re-implement addItem to set dynamic size after add."""
s = QtCore.QSize() apply(QtGui.QListWidget.addItem, (self,) + args)
s.setHeight(super(BufferListWidget,self).sizeHint().height()) self.setMaximumWidth(self.sizeHintForColumn(0) + 4)
s.setWidth(self.sizeHintForColumn(0))
return s
class BufferListWidget(GenericListWidget):
"""Widget with list of buffers."""
def __init__(self, *args):
apply(GenericListWidget.__init__, (self,) + args)
def switch_prev_buffer(self): def switch_prev_buffer(self):
if self.currentRow() > 0: if self.currentRow() > 0:
@ -82,9 +83,7 @@ class BufferWidget(QtGui.QWidget):
self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.chat = ChatTextEdit() self.chat = ChatTextEdit()
self.chat_nicklist.addWidget(self.chat) self.chat_nicklist.addWidget(self.chat)
self.nicklist = QtGui.QListWidget() self.nicklist = GenericListWidget()
self.nicklist.setMaximumWidth(100)
self.nicklist.setFocusPolicy(QtCore.Qt.NoFocus)
if not display_nicklist: if not display_nicklist:
self.nicklist.setVisible(False) self.nicklist.setVisible(False)
self.chat_nicklist.addWidget(self.nicklist) self.chat_nicklist.addWidget(self.nicklist)