QListWidget adjust size to content

Viewed 61451

Is it possible to adjust QListWidget height and width to it's content?

sizeHint() always returns 256, 192 no matter what its content is.
QListWidgetItem's sizeHint() returns -1, -1, so I can not get content width.

Problem the same as here - http://www.qtcentre.org/threads/31787-QListWidget-width , but there is no solution.

enter image description here

import sys
from PyQt4.QtGui import *

class MainWindow(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        list = QListWidget()
        list.addItem('111111111111111')

        vbox = QVBoxLayout(self)
        vbox.addWidget(list)

app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
6 Answers
Related