本文整理汇总了C++中QListView::setCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QListView::setCurrentIndex方法的具体用法?C++ QListView::setCurrentIndex怎么用?C++ QListView::setCurrentIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListView
的用法示例。
在下文中一共展示了QListView::setCurrentIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doubleEditorNegativeInput
void tst_QItemDelegate::doubleEditorNegativeInput()
{
QStandardItemModel model;
QStandardItem *item = new QStandardItem;
item->setData(10.0, Qt::DisplayRole);
model.appendRow(item);
QListView view;
view.setModel(&model);
view.show();
QModelIndex index = model.index(0, 0);
view.setCurrentIndex(index); // the editor will only selectAll on the current index
view.edit(index);
QList<QDoubleSpinBox*> editors = qFindChildren<QDoubleSpinBox *>(view.viewport());
QCOMPARE(editors.count(), 1);
QDoubleSpinBox *editor = editors.at(0);
QCOMPARE(editor->value(), double(10));
QTest::keyClick(editor, Qt::Key_Minus);
QTest::keyClick(editor, Qt::Key_1);
QTest::keyClick(editor, Qt::Key_0);
QTest::keyClick(editor, Qt::Key_Comma); //support both , and . locales
QTest::keyClick(editor, Qt::Key_Period);
QTest::keyClick(editor, Qt::Key_0);
QTest::keyClick(editor, Qt::Key_Enter);
QApplication::processEvents();
QCOMPARE(index.data().toString(), QString("-10"));
}
示例2: editorKeyPress
void tst_QItemDelegate::editorKeyPress()
{
QFETCH(QString, initial);
QFETCH(QString, expected);
QStandardItemModel model;
model.appendRow(new QStandardItem(initial));
QListView view;
view.setModel(&model);
view.show();
QModelIndex index = model.index(0, 0);
view.setCurrentIndex(index); // the editor will only selectAll on the current index
view.edit(index);
QList<QLineEdit*> lineEditors = qFindChildren<QLineEdit *>(view.viewport());
QCOMPARE(lineEditors.count(), 1);
QLineEdit *editor = lineEditors.at(0);
QCOMPARE(editor->selectedText(), initial);
QTest::keyClicks(editor, expected);
QTest::keyClick(editor, Qt::Key_Enter);
QApplication::processEvents();
QCOMPARE(index.data().toString(), expected);
}
示例3: mapChanged
// Type: 0 = static, 1 = mission
void HWMapContainer::mapChanged(const QModelIndex & map, int type, const QModelIndex & old)
{
QListView * mapList;
if (type == 0) mapList = staticMapList;
else if (type == 1) mapList = missionMapList;
else return;
// Make sure it is a valid index
if (!map.isValid())
{
if (old.isValid())
{
mapList->setCurrentIndex(old);
mapList->scrollTo(old);
}
else
{
m_mapInfo.type = MapModel::Invalid;
updatePreview();
}
return;
}
// If map changed, update list selection
if (mapList->currentIndex() != map)
{
mapList->setCurrentIndex(map);
mapList->scrollTo(map);
}
if (map.data(Qt::UserRole + 1).canConvert<MapModel::MapInfo>())
setMapInfo(map.data(Qt::UserRole + 1).value<MapModel::MapInfo>());
else
Q_ASSERT(false); // Houston, we have a problem.
}
示例4: bodyclicked
void MainWindow::bodyclicked(int bodyIndex)
{
indexSelected = bodyIndex;
QListView * objectList = findChild<QListView*>(QString("objectList"));
if(indexSelected == -1) //used clicked on empty space
{
objectList->clearSelection();
}
else
{
QModelIndex qIndex = objectListSource->index(indexSelected);
objectList->setCurrentIndex(qIndex);
}
}
示例5: QCOMPARE
void tst_QFontDialog::task256466_wrongStyle()
{
QFontDatabase fdb;
FriendlyFontDialog dialog;
QListView *familyList = reinterpret_cast<QListView*>(dialog.d_func()->familyList);
QListView *styleList = reinterpret_cast<QListView*>(dialog.d_func()->styleList);
QListView *sizeList = reinterpret_cast<QListView*>(dialog.d_func()->sizeList);
for (int i = 0; i < familyList->model()->rowCount(); ++i) {
QModelIndex currentFamily = familyList->model()->index(i, 0);
familyList->setCurrentIndex(currentFamily);
const QFont current = dialog.currentFont(),
expected = fdb.font(currentFamily.data().toString(),
styleList->currentIndex().data().toString(), sizeList->currentIndex().data().toInt());
QCOMPARE(current.family(), expected.family());
QCOMPARE(current.style(), expected.style());
QCOMPARE(current.pointSizeF(), expected.pointSizeF());
}
}
示例6: enterKey
void tst_QItemDelegate::enterKey()
{
QFETCH(WidgetType, widget);
QFETCH(int, key);
QFETCH(bool, expectedFocus);
QStandardItemModel model;
model.appendRow(new QStandardItem());
QListView view;
view.setModel(&model);
view.show();
QApplication::setActiveWindow(&view);
view.setFocus();
QTest::qWait(30);
struct TestDelegate : public QItemDelegate
{
WidgetType widgetType;
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
{
QWidget *editor = 0;
switch(widgetType) {
case LineEdit:
editor = new QLineEdit(parent);
break;
case TextEdit:
editor = new QTextEdit(parent);
break;
case PlainTextEdit:
editor = new QPlainTextEdit(parent);
break;
}
editor->setObjectName(QString::fromLatin1("TheEditor"));
return editor;
}
} delegate;
delegate.widgetType = widget;
view.setItemDelegate(&delegate);
QModelIndex index = model.index(0, 0);
view.setCurrentIndex(index); // the editor will only selectAll on the current index
view.edit(index);
QTest::qWait(30);
QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor"));
QCOMPARE(lineEditors.count(), 1);
QPointer<QWidget> editor = lineEditors.at(0);
QCOMPARE(editor->hasFocus(), true);
QTest::keyClick(editor, Qt::Key(key));
QApplication::processEvents();
// The line edit has already been destroyed, so avoid that case.
if (widget == TextEdit || widget == PlainTextEdit) {
QVERIFY(!editor.isNull());
QCOMPARE(editor && editor->hasFocus(), expectedFocus);
}
}