1

I was playing with the Config Dialog Example, all was fine. Then I changed something in the right part of the dialog. Then I found the contentsWidget (QListWidget) in the left part of the dialog became smaller and showed the scroll bars (both Horizontal and Vertical).

I want the QListWidget to show all its content so that no scroll bars are needed. All items are added at the beginning and fixed. No dynamic. I guess there is a simply method to let the QListWidget expand to show all its content at the beginning.

Could anyone help me and tell me the magic word?

Here is the code:

contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode);
contentsWidget->setIconSize(QSize(96, 84));
contentsWidget->setMovement(QListView::Static);
contentsWidget->setMaximumWidth(128);
contentsWidget->setSpacing(12);
//contentsWidget->setMinimumWidth(contentsWidget->sizeHintForColumn(0));
//contentsWidget->setMaximumWidth(contentsWidget->sizeHintForColumn(0));
//contentsWidget->adjustSize();
//qDebug()<<contentsWidget->sizeHintForColumn(0);
createIcons();
contentsWidget->setCurrentRow(0);

QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(contentsWidget);
horizontalLayout->addWidget(pagesWidget, 1);

I tried contentsWidget->sizeHintForColumn(0), but it didn't work. It was 0. I tried some other methods but nothing worked.

Boris Dalstein
  • 7,015
  • 4
  • 30
  • 59
Kelvin Gan
  • 41
  • 2

1 Answers1

-2

I think you should try:

contentsWidget->setMinimumWidth(128);

This will ensure that no matters what, the size of contentsWidget will always be at least 128, hence large enough to contains the icons.

Boris Dalstein
  • 7,015
  • 4
  • 30
  • 59