Is there a way to ensure that the whole text under an QListWidgetItem is displayed when I enable uniformItemSizes ?
EDIT: Nevermind, i just found the solution:
I studied the source code from Kontact and a few moments later I extended me source code with this: (unfortunately I've coded my application in Python, but it shouldn't be hard to covert this to C++):
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ui_mainwindow
class MainWindow
(QMainWindow, ui_mainwindow.
Ui_MainWindow): def __init__(self, parent):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
for i in range(self.listWidget.count()):
itemSize = QStyledItemDelegate().sizeHint( self.listWidget.viewOptions(), self.listWidget.indexFromItem(self.listWidget.item(i)) )
if itemSize.width() > maxSize.width():
maxSize.setWidth(itemSize.width())
if itemSize.height() > maxSize.height():
maxSize.setHeight(itemSize.height())
maxSize.setWidth(maxSize.width() + 5) # Just some spacing
for i in range(self.listWidget.count()):
self.listWidget.item(i).setSizeHint(maxSize)
self.listWidget.setGridSize(maxSize)
self.listWidget.setMaximumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
self.listWidget.setMinimumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
self.show()
w = MainWindow(None)
app.exec_()
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ui_mainwindow
class MainWindow(QMainWindow, ui_mainwindow.Ui_MainWindow):
def __init__(self, parent):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
maxSize = QSize()
for i in range(self.listWidget.count()):
itemSize = QStyledItemDelegate().sizeHint( self.listWidget.viewOptions(), self.listWidget.indexFromItem(self.listWidget.item(i)) )
if itemSize.width() > maxSize.width():
maxSize.setWidth(itemSize.width())
if itemSize.height() > maxSize.height():
maxSize.setHeight(itemSize.height())
maxSize.setWidth(maxSize.width() + 5) # Just some spacing
for i in range(self.listWidget.count()):
self.listWidget.item(i).setSizeHint(maxSize)
self.listWidget.setGridSize(maxSize)
self.listWidget.setMaximumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
self.listWidget.setMinimumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
self.show()
app = QApplication([])
w = MainWindow(None)
app.exec_()
To copy to clipboard, switch view to plain text mode
For everybody who wants to do a similar thing I attatched my final *.ui file and made an screenshot:
Bookmarks