本文整理汇总了C++中QListWidget::setViewMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::setViewMode方法的具体用法?C++ QListWidget::setViewMode怎么用?C++ QListWidget::setViewMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::setViewMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QListWidget
/** Creates and sets up list widget.
* \return Poiter to created list widget.
* \sa insertItem()
*/
QListWidget *OptionsDialog::createListWidget() {
QListWidget *listWidget = new QListWidget(this);
insertItems(listWidget);
listWidget->setObjectName(QString::fromUtf8("listWidget"));
listWidget->setMaximumWidth(120);
listWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
listWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
listWidget->setFlow(QListView::LeftToRight);
listWidget->setGridSize(QSize(110, 60));
listWidget->setViewMode(QListView::IconMode);
return listWidget;
}
示例2: fm
QWidget *ConfigDialog::centerWidget()
{
/*
m_pagesTabWidget = new QTabWidget;
for (int i = 0; i < m_pageWidgets.size(); ++i)
m_pagesTabWidget->addTab(m_pageWidgets.at(i), m_pageTitles.at(i));
return m_pagesTabWidget;
*/
// create list
QListWidget *pagesListWidget = new QListWidget;
pagesListWidget->setViewMode(QListView::IconMode);
pagesListWidget->setMovement(QListView::Static);
pagesListWidget->setFlow(QListView::TopToBottom);
pagesListWidget->setWordWrap(true);
pagesListWidget->setUniformItemSizes(true);
pagesListWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
// add items to list
QFontMetrics fm(qApp->font());
int iconWidth = 0;
for (int i = 0; i < m_pagesListWidgetItems.size(); ++i)
iconWidth = qMax(iconWidth, fm.boundingRect(0, 0, 0, 0, Qt::AlignCenter, m_pagesListWidgetItems.at(i)->text()).width());
iconWidth += 20;
const int iconHeight = fm.height() + 42;
for (int i = 0; i < m_pagesListWidgetItems.size(); ++i)
{
m_pagesListWidgetItems.at(i)->setSizeHint(QSize(iconWidth, iconHeight));
pagesListWidget->addItem(m_pagesListWidgetItems.at(i));
}
pagesListWidget->setFixedWidth(m_pagesListWidgetItems.at(0)->sizeHint().width() + 6);
// create title
QFrame *titleFrame = new QFrame(this);
// titleFrame->setAutoFillBackground(true);
// titleFrame->setFrameShape(QFrame::StyledPanel);
titleFrame->setFrameShape(QFrame::Box);
// titleFrame->setFrameShadow(QFrame::Plain);
// titleFrame->setBackgroundRole(QPalette::Base);
m_pagesTitleLabel = new QLabel(titleFrame);
m_pagesTitleLabel->setStyleSheet("QLabel { font-weight: bold; }");
QGridLayout *titleLayout = new QGridLayout(titleFrame);
titleLayout->setColumnStretch(0, 1);
titleLayout->setMargin(6);
titleLayout->addWidget(m_pagesTitleLabel);
// add pages
QStackedWidget *pagesStackedWidget = new QStackedWidget;
for (int i = 0; i < m_pageWidgets.size(); ++i)
pagesStackedWidget->addWidget(m_pageWidgets.at(i));
connect(pagesListWidget, SIGNAL(currentRowChanged(int)), pagesStackedWidget, SLOT(setCurrentIndex(int)));
connect(pagesListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setCurrentPage(int)));
pagesListWidget->setCurrentRow(0);
QWidget *mainWidget = new QWidget;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(pagesListWidget, 0, 0, 2, 1);
mainLayout->addWidget(titleFrame, 0, 1);
mainLayout->addWidget(pagesStackedWidget, 1, 1);
mainWidget->setLayout(mainLayout);
return mainWidget;
}