【问题标题】:Init QListWidget to show its all content (with no scroll bars)初始化 QListWidget 以显示其所有内容(没有滚动条)
【发布时间】:2013-07-18 01:36:39
【问题描述】:

我在玩Config Dialog Example,一切都很好。然后我在对话框的右侧更改了一些内容。 然后我发现对话框左侧的contentsWidget (QListWidget) 变小了,并显示了滚动条(水平和垂直)。

我希望 QListWidget 显示其所有内容,这样就不需要滚动条。 所有项目都在开头添加并固定。没有动态。 我想有一种简单的方法可以让 QListWidget 展开以在开头显示其所有内容。

谁能帮我告诉我这个神奇的词?

代码如下:

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);

我试过contentsWidget-&gt;sizeHintForColumn(0),但没用。为 0。我尝试了其他一些方法,但没有任何效果。

【问题讨论】:

标签: qt qlistwidget


【解决方案1】:

我觉得你应该试试:

contentsWidget->setMinimumWidth(128);

这将确保无论如何,contentsWidget 的大小始终至少为 128,因此足以容纳图标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    相关资源
    最近更新 更多