本文整理汇总了C++中QListView::selectionModel方法的典型用法代码示例。如果您正苦于以下问题:C++ QListView::selectionModel方法的具体用法?C++ QListView::selectionModel怎么用?C++ QListView::selectionModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListView
的用法示例。
在下文中一共展示了QListView::selectionModel方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_removeItems
void GraphicalArrayTest::test_removeItems()
{
GraphicalArray * value = new GraphicalArray();
QPushButton * button = findRemoveButton(value);
QStringListModel * model = findModel(value);
QListView * view = findListView(value);
QItemSelectionModel::SelectionFlags flag = QItemSelectionModel::Select;
model->setStringList( QStringList() << "Hello" << "World" << "and" << "Happy" << "New" << "Year!" );
value->show();
view->selectionModel()->select( model->index(0), flag ); // select "Hello"
view->selectionModel()->select( model->index(1), flag ); // select "World"
view->selectionModel()->select( model->index(3), flag ); // select "Happy"
view->selectionModel()->select( model->index(5), flag ); // select "Year"
// simulate a click on the 'Remove' button
QTest::mouseClick( button, Qt::LeftButton );
QStringList values = model->stringList();
QCOMPARE( values.count(), 2 );
QCOMPARE( values.at(0), QString("and") );
QCOMPARE( values.at(1), QString("New") );
delete value;
}
示例2: loadSearch
void MediaListsManager::loadSearch()
{
Ui::MainWindowClass* ui = m_application->mainWindow()->ui;
ui->mediaView->setFocus();
QListView* audioLists = m_application->mainWindow()->audioListsStack()->ui->audioLists;
audioLists->selectionModel()->clearSelection();
QListView* videoLists = m_application->mainWindow()->videoListsStack()->ui->videoLists;
videoLists->selectionModel()->clearSelection();
if (!ui->Filter->text().isEmpty()) {
addListToHistory();
if (m_mediaListSelection == MediaListsManager::AudioList) {
MediaListProperties searchProperties;
searchProperties.name = i18n("Audio Search");
searchProperties.lri = QString("music://search?%1").arg(ui->Filter->text());
m_application->browsingModel()->clearMediaListData();
m_application->browsingModel()->setMediaListProperties(searchProperties);
m_application->browsingModel()->load();
} else {
MediaListProperties searchProperties;
searchProperties.name = i18n("Video Search");
searchProperties.lri = QString("video://search?%1").arg(ui->Filter->text());
m_application->browsingModel()->clearMediaListData();
m_application->browsingModel()->setMediaListProperties(searchProperties);
m_application->browsingModel()->load();
}
}
}
示例3: uintEdit
void tst_QItemDelegate::uintEdit()
{
QListView view;
QStandardItemModel model;
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(0, 0, data);
}
{
QStandardItem *data=new QStandardItem;
data->setEditable(true);
data->setData(QVariant((uint)1), Qt::DisplayRole);
model.setItem(1, 0, data);
}
view.setModel(&model);
view.setEditTriggers(QAbstractItemView::AllEditTriggers);
const QModelIndex firstCell = model.index(0, 0);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
view.selectionModel()->setCurrentIndex(model.index(0, 0), QItemSelectionModel::Select);
view.edit(firstCell);
QSpinBox *sb = view.findChild<QSpinBox*>();
QVERIFY(sb);
sb->stepUp();
// Select another index to trigger the end of editing.
const QModelIndex secondCell = model.index(1, 0);
view.selectionModel()->setCurrentIndex(secondCell, QItemSelectionModel::Select);
QCOMPARE(firstCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(firstCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(2));
view.edit(secondCell);
// The first spinbox is deleted with deleteLater, so it is still there.
QList<QSpinBox*> sbList = view.findChildren<QSpinBox*>();
QCOMPARE(sbList.size(), 2);
sb = sbList.at(1);
sb->stepDown(); // 1 -> 0
sb->stepDown(); // 0 (no effect)
sb->stepDown(); // 0 (no effect)
// Select another index to trigger the end of editing.
view.selectionModel()->setCurrentIndex(firstCell, QItemSelectionModel::Select);
QCOMPARE(secondCell.data(Qt::DisplayRole).userType(), static_cast<int>(QMetaType::UInt));
QCOMPARE(secondCell.data(Qt::DisplayRole).toUInt(), static_cast<uint>(0));
}
示例4: selectVideoList
void MediaListsManager::selectVideoList()
{
Ui::MainWindowClass* ui = m_application->mainWindow()->ui;
showMediaList(VideoList);
m_application->mainWindow()->videoListsStack()->ui->videoListsStack->setCurrentIndex(0);
QListView* videoLists = m_application->mainWindow()->videoListsStack()->ui->videoLists;
if (videoLists->selectionModel()->selectedIndexes().count() > 0){
int selectedRow = videoLists->selectionModel()->selectedIndexes().at(0).row();
loadMediaList(m_videoListsModel, selectedRow);
}
m_application->mainWindow()->videoListsStack()->ui->videoLists->setFocus();
ui->Filter->setClickMessage(i18n("Search for video"));
ui->Filter->clear();
}
示例5: slotDeleteSelected
void VegetationWidget::slotDeleteSelected()
{
QListView* view = qobject_cast<QListView*>(sender());
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(view->model());
QString dirString("");
if (view == _treeListView)
{
std::string plantDir = g_SystemContext._workContextDir;
plantDir.append(CONTEXT_DIR);
plantDir.append("/Plant/");
dirString = chineseTextUTF8ToQString(plantDir + "Tree/");
}
else
{
std::string plantDir = g_SystemContext._workContextDir;
plantDir.append(CONTEXT_DIR);
plantDir.append("/Plant/");
dirString = chineseTextUTF8ToQString(plantDir + "Grass/");
}
QItemSelectionModel* selectionModel = view->selectionModel();
QModelIndexList modelList = selectionModel->selectedIndexes();
if (modelList.size() < 1)
return;
for (int i = 0; i < modelList.size(); ++i)
{
QStandardItem* everyItem = model->itemFromIndex(modelList.at(i));
QFile::remove(dirString + everyItem->text());
int row = everyItem->row();
model->removeRow(row);
}
}
示例6: videoListsChanged
void MediaListsManager::videoListsChanged()
{
QModelIndex index = m_videoListsModel->index(0, 0);
if (index.isValid()) {
QListView* videoLists = m_application->mainWindow()->videoListsStack()->ui->videoLists;
videoLists->selectionModel()->select( index, QItemSelectionModel::Select );
}
}
示例7: on_deleteButton_clicked
void MessagePage::on_deleteButton_clicked()
{
QListView *list = ui->listConversation;
if(!list->selectionModel())
return;
QModelIndexList indexes = list->selectionModel()->selectedIndexes();
if(!indexes.isEmpty())
{
list->model()->removeRow(indexes.at(0).row());
indexes = list->selectionModel()->selectedIndexes();
if(indexes.isEmpty())
on_backButton_clicked();
}
}
示例8: slotViewSelected
void VegetationWidget::slotViewSelected()
{
QListView* view = qobject_cast<QListView*>(sender());
QItemSelectionModel* selectionModel = view->selectionModel();
QModelIndexList modelList = selectionModel->selectedIndexes();
if (modelList.size() < 1)
return;
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(view->model());
std::string dirString("");
if (view == _treeListView)
{
std::string plantDir = g_SystemContext._workContextDir;
plantDir.append(CONTEXT_DIR);
plantDir.append("/Plant/");
dirString = plantDir + "Tree/";
}
else
{
std::string plantDir = g_SystemContext._workContextDir;
plantDir.append(CONTEXT_DIR);
plantDir.append("/Plant/");
dirString = plantDir + "Grass/";
}
QStandardItem* currentItem = model->itemFromIndex(modelList.at(0));
dirString.append(chineseTextToUTF8String(currentItem->text()));
osg::ref_ptr<osg::Node> node;
if (currentItem->text().endsWith(".osgb"))
{
node = g_SystemContext._resourceLoader->getNodeByName(dirString, false);
}
else
{
osg::ref_ptr<osg::Image> image = g_SystemContext._resourceLoader->getImageByFileName(dirString);
if (image.valid())
{
float s = image->s();
float t = image->t();
osg::ref_ptr<osg::Geometry> geometry = osg::createTexturedQuadGeometry(osg::Vec3(-s / 2.0f, -t / 2.0f, 0), osg::Vec3(s, 0, 0), osg::Vec3(0, t, 0));
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(geometry);
osg::StateSet* ss = geode->getOrCreateStateSet();
ss->setMode(GL_BLEND, osg::StateAttribute::ON);
ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::Texture2D* texture = new osg::Texture2D(image);
ss->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
node = geode;
}
}
if (node.valid())
{
_nodeViewDialog = new NodeViewDialog;
_nodeViewDialog->setNode(node);
_nodeViewDialog->exec();
//_nodeViewDialog->setNode(NULL);
}
}
示例9: QMainWindow
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
QMenu *itemsMenu = new QMenu(tr("&Items"));
insertAction = itemsMenu->addAction(tr("&Insert Item"));
removeAction = itemsMenu->addAction(tr("&Remove Item"));
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(itemsMenu);
QStringList numbers;
numbers << tr("One") << tr("Two") << tr("Three") << tr("Four") << tr("Five")
<< tr("Six") << tr("Seven") << tr("Eight") << tr("Nine") << tr("Ten");
model = new StringListModel(numbers);
QListView *view = new QListView(this);
view->setModel(model);
selectionModel = view->selectionModel();
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));
connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));
connect(selectionModel,
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(updateMenus(const QModelIndex &)));
setCentralWidget(view);
setWindowTitle("View onto a string list model");
}
示例10: QObject
MediaListsManager::MediaListsManager(MainWindow* parent) : QObject(parent)
{
m_application = (BangarangApplication*)KApplication::kApplication();
Ui::MainWindowClass* ui = m_application->mainWindow()->ui;
//Set up Audio lists view
MediaListProperties audioListsProperties;
audioListsProperties.lri = "medialists://audio";
m_audioListsModel = new MediaItemModel(this);
m_audioListsModel->setMediaListProperties(audioListsProperties);
QListView* audioLists = m_application->mainWindow()->audioListsStack()->ui->audioLists;
audioLists->setModel(m_audioListsModel);
connect(audioLists->selectionModel(), SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)), this, SLOT(audioListsSelectionChanged(const QItemSelection, const QItemSelection)));
connect(m_audioListsModel, SIGNAL(mediaListChanged()), this, SLOT(audioListsChanged()));
m_audioListsModel->load();
QToolButton* audioListSelect = m_application->mainWindow()->ui->audioListSelect;
connect(audioListSelect, SIGNAL(clicked()), this, SLOT(selectAudioList()));
//Set up Video lists view
MediaListProperties videoListsProperties;
videoListsProperties.lri = "medialists://video";
m_videoListsModel = new MediaItemModel(this);
m_videoListsModel->setMediaListProperties(videoListsProperties);
QListView* videoLists = m_application->mainWindow()->videoListsStack()->ui->videoLists;
videoLists->setModel(m_videoListsModel);
connect(videoLists->selectionModel(), SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)), this, SLOT(videoListsSelectionChanged(const QItemSelection, const QItemSelection)));
connect(m_videoListsModel, SIGNAL(mediaListChanged()), this, SLOT(videoListsChanged()));
m_videoListsModel->load();
QToolButton* videoListSelect = m_application->mainWindow()->ui->videoListSelect;
connect(videoListSelect, SIGNAL(clicked()), this, SLOT(selectVideoList()));
//Set up media list view
m_loadingProgress = 0;
MediaView* mediaView = ui->mediaView;
mediaView->setMainWindow(m_application->mainWindow());
mediaView->setSourceModel(m_application->browsingModel());
connect(m_application->browsingModel(), SIGNAL(mediaListChanged()), this, SLOT(mediaListChanged()));
connect(m_application->browsingModel(), SIGNAL(mediaListPropertiesChanged()), this, SLOT(mediaListPropertiesChanged()));
connect(m_application->browsingModel(), SIGNAL(loading()), this, SLOT(mediaListLoading()));
connect(m_application->browsingModel(), SIGNAL(loadingStateChanged(bool)), this, SLOT(mediaListLoadingStateChanged(bool)));
connect(m_application->browsingModel(), SIGNAL(propertiesChanged()), this, SLOT(updateListHeader()));
connect((MediaItemDelegate *)mediaView->itemDelegate(), SIGNAL(categoryActivated(QModelIndex)), this, SLOT(mediaListCategoryActivated(QModelIndex)));
connect((MediaItemDelegate *)mediaView->itemDelegate(), SIGNAL(actionActivated(QModelIndex)), this, SLOT(mediaListActionActivated(QModelIndex)));
connect(mediaView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)), this, SLOT(mediaSelectionChanged(const QItemSelection, const QItemSelection)));
connect(ui->previous, SIGNAL(clicked()), this, SLOT(loadPreviousList()));
connect(m_application->playlist()->nowPlayingModel(), SIGNAL(mediaListChanged()), this, SLOT(nowPlayingChanged()));
connect(m_application->mainWindow(), SIGNAL(switchedMainWidget(MainWindow::MainWidget)), this, SLOT(defaultListLoad(MainWindow::MainWidget)));
//Setup media list filter
ui->mediaListFilterProxyLine->lineEdit()->setClickMessage(QString());
ui->mediaListFilterProxyLine->setProxy(ui->mediaView->filterProxyModel());
ui->mediaListFilter->setVisible(false);
connect(ui->closeMediaListFilter, SIGNAL(clicked()), this, SLOT(closeMediaListFilter()));
//Set up play select/all buttons
connect(ui->playAll, SIGNAL(clicked()), this, SLOT(playAll()));
connect(ui->playSelected, SIGNAL(clicked()), this, SLOT(playSelected()));
//Setup browsing model status notifications
connect(m_application->browsingModel(), SIGNAL(statusUpdated()), this, SLOT(browsingModelStatusUpdated()));
//Set up search
KLineEdit* searchField = m_application->mainWindow()->ui->Filter;
connect(searchField, SIGNAL(returnPressed()), this, SLOT(loadSearch()));
//Set up device notifier
connect(DeviceManager::instance(), SIGNAL(deviceListChanged(DeviceManager::RelatedType)),
this, SLOT(updateDeviceList(DeviceManager::RelatedType)));
//Set default media list selection
showMediaList(AudioList);
}
示例11: QDialog
::fwActivities::registry::ActivityInfo SCreateActivity::show( const ActivityInfoContainer& infos )
{
QWidget* parent = qApp->activeWindow();
QDialog* dialog = new QDialog(parent);
dialog->setWindowTitle(QString::fromStdString("Choose an activity"));
dialog->resize(600, 400);
QStandardItemModel* model = new QStandardItemModel(dialog);
for( const ::fwActivities::registry::ActivityInfo& info : infos)
{
std::string text;
if(info.title.empty())
{
text = info.id;
}
else
{
text = info.title + (info.description.empty() ? "" : "\n" + info.description);
}
QStandardItem* item = new QStandardItem(QIcon(info.icon.c_str()), QString::fromStdString(text));
item->setData(QVariant::fromValue(info));
item->setEditable(false);
model->appendRow(item);
}
QListView* selectionList = new QListView();
selectionList->setIconSize(QSize(40, 40));
selectionList->setUniformItemSizes(true);
selectionList->setModel(model);
QModelIndex index = model->index( 0, 0 );
if ( index.isValid() )
{
selectionList->selectionModel()->select( index, QItemSelectionModel::Select );
}
QPushButton* okButton = new QPushButton("Ok");
QPushButton* cancelButton = new QPushButton("Cancel");
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->addWidget(okButton);
hLayout->addWidget(cancelButton);
QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->addWidget(selectionList);
vLayout->addLayout(hLayout);
dialog->setLayout(vLayout);
QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
QObject::connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
QObject::connect(selectionList, SIGNAL(doubleClicked(const QModelIndex&)), dialog, SLOT(accept()));
::fwActivities::registry::ActivityInfo info;
if(dialog->exec())
{
QModelIndex currentIndex = selectionList->selectionModel()->currentIndex();
QStandardItem* item = model->itemFromIndex( currentIndex );
QVariant var = item->data();
info = var.value< ::fwActivities::registry::ActivityInfo >();
}
return info;
}
示例12: add_elem
void AddVarDialog::add_elem(QString name)
{
const QModelIndex& plant_index = plants_widget->selectionModel()->currentIndex();
plants_model->addVar(plant_index, name);
}
示例13: QFileDialog
MultiQFileDialog::MultiQFileDialog(QWidget *parent, const QString &caption, const QString &directory, bool multiSelect, const QString &filter)
: QFileDialog(parent, caption, directory, filter)
{
this->showHidden = false;
this->multiSelect = multiSelect;
setOption(QFileDialog::DontUseNativeDialog, false);
if (multiSelect)
{
setOption(QFileDialog::DontUseNativeDialog, true);
le = findChild<QLineEdit*>(QString::fromUtf8("fileNameEdit"));
QListView *l = findChild<QListView*>(QString::fromUtf8("listView"));
if (l)
{
l->setSelectionMode(QListView::ExtendedSelection);
if (le)
{
connect(l->selectionModel(),
SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
this,
SLOT(onSelectionChanged ( const QItemSelection &, const QItemSelection & )));
}
}
QTreeView *t = findChild<QTreeView*>();
if (t)
{
t->setSelectionMode(QAbstractItemView::ExtendedSelection);
if (le)
{
connect(t->selectionModel(),
SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
this,
SLOT(onSelectionChanged ( const QItemSelection &, const QItemSelection & )));
}
}
QLabel *label = findChild<QLabel*>(QString::fromUtf8("fileNameLabel"));
if (label)
{
label->hide();
}
label = findChild<QLabel*>(QString::fromUtf8("fileTypeLabel"));
if (label)
{
label->hide();
}
label = findChild<QLabel*>(QString::fromUtf8("lookInLabel"));
if (label)
{
label->hide();
}
QDialogButtonBox *buttonBox = findChild<QDialogButtonBox*>(QString::fromUtf8("buttonBox"));
if (buttonBox)
{
buttonBox->button(QDialogButtonBox::Open)->setText(QCoreApplication::translate("QDialogButtonBox", "&OK"));
}
setFileMode(QFileDialog::ExistingFiles);
if (le)
{
le->setText(QCoreApplication::translate("ShellExtension", "Upload to MEGA"));
}
}
QList<QWidget *> widgets = findChildren<QWidget *>();
for (QList<QWidget *>::const_iterator it = widgets.begin(); it != widgets.end(); ++it)
{
(*it)->installEventFilter(this);
}
installEventFilter(this);
}