本文整理汇总了C++中QAbstractItemView类的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView类的具体用法?C++ QAbstractItemView怎么用?C++ QAbstractItemView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAbstractItemView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QVERIFY
void tst_QColumnView::clicked()
{
ColumnView view;
QDirModel model;
view.setModel(&model);
view.resize(800,300);
view.show();
QModelIndex home = model.index(QDir::homePath());
QVERIFY(home.isValid());
view.setCurrentIndex(home);
QTest::qWait(ANIMATION_DELAY);
QModelIndex parent = home.parent();
QVERIFY(parent.isValid());
qRegisterMetaType<QModelIndex>("QModelIndex");
QSignalSpy clickedSpy(&view, SIGNAL(clicked(const QModelIndex &)));
QPoint localPoint = view.visualRect(home).center();
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
QCOMPARE(clickedSpy.count(), 1);
qApp->processEvents();
if (sizeof(qreal) != sizeof(double)) {
QSKIP("Skipped due to rounding errors", SkipAll);
}
for (int i = 0; i < view.createdColumns.count(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
if (column && column->selectionModel() && (column->rootIndex() == home))
QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
}
}
示例2: slotActivatedOnlyDirs
/*
* This slot uses for setting root index in a current view only if a dir was activated.
* If there are trying to activate a file, nothing will be done.
*/
void MainWindow::slotActivatedOnlyDirs(const QModelIndex &index)
{
QAbstractItemView *view = 0;
if (isDir(index) && (view = dynamic_cast<QAbstractItemView *>(sender()) ) )
view->setRootIndex(index);
resetRightView(index);
}
示例3: QComboBox
QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QComboBox *comboDelegate = new QComboBox(parent);
comboDelegate->setModel(model);
comboDelegate->setEditable(true);
comboDelegate->setAutoCompletion(true);
comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion);
comboDelegate->view()->setEditTriggers(QAbstractItemView::AllEditTriggers);
comboDelegate->lineEdit()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
comboDelegate->view()->installEventFilter(const_cast<QObject *>(qobject_cast<const QObject *>(this)));
QAbstractItemView *comboPopup = comboDelegate->lineEdit()->completer()->popup();
comboPopup->setMouseTracking(true);
connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString)));
connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation()));
connect(comboPopup, SIGNAL(entered(QModelIndex)), this, SLOT(testActivation(QModelIndex)));
connect(comboPopup, SIGNAL(activated(QModelIndex)), this, SLOT(fakeActivation()));
currCombo.comboEditor = comboDelegate;
currCombo.currRow = index.row();
currCombo.model = const_cast<QAbstractItemModel *>(index.model());
keyboardFinished = false;
// Current display of things on Gnome3 looks like shit, so
// let`s fix that.
if (isGnome3Session()) {
QPalette p;
p.setColor(QPalette::Window, QColor(Qt::white));
p.setColor(QPalette::Base, QColor(Qt::white));
comboDelegate->lineEdit()->setPalette(p);
comboDelegate->setPalette(p);
}
return comboDelegate;
}
示例4: paint
void FilterItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent());
QLabel *label;
if (view->indexWidget(index) == 0)
{
label = new QLabel();
label->installEventFilter(filter);
label->setAutoFillBackground(true);
label->setFocusPolicy(Qt::TabFocus);
label->setText(index.data().toString());
view->setIndexWidget(index, label);
}
label = (QLabel*)view->indexWidget(index);
if (option.state & QStyle::State_Selected)
if (option.state & QStyle::State_HasFocus)
label->setBackgroundRole(QPalette::Highlight);
else
label->setBackgroundRole(QPalette::Window);
else
label->setBackgroundRole(QPalette::Base);
}
示例5: QMainWindow
HistoryWindow::HistoryWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::HistoryWindow)
{
ui->setupUi(this);
connect(FlowMeterManager::Instance, SIGNAL(PourFinished()), this, SLOT(pourFinishedSlot()));
connect(this->ui->scrollPane, SIGNAL(SelectionChanged(int)), this, SLOT(setSelectedIndex(int)));
picIndex = 0;
selectedIndex = -1;
selectedPour = NULL;
QAbstractItemView *view = this->ui->usersComboBox->view();
view->setItemDelegate(new CustomComboBoxItem(this));
connect(this->ui->usersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(userSelectedSlot(int)));
vector<User*>::iterator iter;
for (iter = User::UsersList.begin(); iter != User::UsersList.end(); ++iter)
{
User* user = (*iter);
this->ui->usersComboBox->addItem(QString(user->Name.c_str()));
}
this->ui->usersComboBox->setCurrentIndex(-1);
//QtConcurrent::run(this, &HistoryWindow::updateButtons);
}
示例6: verifyCurrentItemAndSelection
/** A method that simplifies checking a view's current item and selection */
static void verifyCurrentItemAndSelection(const QAbstractItemView& view, const QModelIndex& expectedCurrent, const QModelIndexList& expectedSelection) {
QCOMPARE(view.currentIndex(), expectedCurrent);
const QModelIndexList selectedIndexes = view.selectionModel()->selectedIndexes();
QCOMPARE(selectedIndexes.count(), expectedSelection.count());
foreach(const QModelIndex& index, expectedSelection) {
QVERIFY(selectedIndexes.contains(index));
}
示例7: cacheSectionMinSizes
void RDHeaderView::cacheSectionMinSizes()
{
m_sectionMinSizes.resize(count());
m_sectionMinSizesTotal = 0;
for(int i = 0; i < m_sectionMinSizes.count(); i++)
{
int sz = 0;
// see if we can fetch the column/row size hint from the item view
QAbstractItemView *view = qobject_cast<QAbstractItemView *>(parent());
if(view)
{
if(orientation() == Qt::Horizontal)
sz = view->sizeHintForColumn(i);
else
sz = view->sizeHintForRow(i);
}
// also include the size for the header as another minimum
if(orientation() == Qt::Horizontal)
sz = qMax(sz, sectionSizeFromContents(i).width());
else
sz = qMax(sz, sectionSizeFromContents(i).height());
// finally respect the minimum section size specified
sz = qMax(sz, minimumSectionSize());
// update the minimum size for this section and count the total which we'll need
m_sectionMinSizes[i] = sz;
m_sectionMinSizesTotal += m_sectionMinSizes[i];
}
}
示例8: currentWidget
QList<std::shared_ptr<const UICommon::GameFile>> GameList::GetSelectedGames() const
{
QAbstractItemView* view;
QSortFilterProxyModel* proxy;
if (currentWidget() == m_list)
{
view = m_list;
proxy = m_list_proxy;
}
else
{
view = m_grid;
proxy = m_grid_proxy;
}
QList<std::shared_ptr<const UICommon::GameFile>> selected_list;
QItemSelectionModel* sel_model = view->selectionModel();
if (sel_model->hasSelection())
{
QModelIndexList index_list =
currentWidget() == m_list ? sel_model->selectedRows() : sel_model->selectedIndexes();
for (const auto& index : index_list)
{
QModelIndex model_index = proxy->mapToSource(index);
selected_list.push_back(m_model->GetGameFile(model_index.row()));
}
}
return selected_list;
}
示例9: QFETCH
void tst_QColumnView::moveGrip()
{
QFETCH(bool, reverse);
if (reverse)
qApp->setLayoutDirection(Qt::RightToLeft);
ColumnView view;
TreeModel model;
view.setModel(&model);
QModelIndex home = model.thirdLevel();
view.setCurrentIndex(home);
view.resize(640, 200);
view.show();
QTest::qWait(ANIMATION_DELAY);
int columnNum = view.createdColumns.count() - 2;
QVERIFY(columnNum >= 0);
QObjectList list = view.createdColumns[columnNum]->children();
QColumnViewGrip *grip = 0;
for (int i = 0; i < list.count(); ++i) {
if ((grip = qobject_cast<QColumnViewGrip *>(list[i]))) {
break;
}
}
if (!grip)
return;
QAbstractItemView *column = qobject_cast<QAbstractItemView *>(grip->parent());
int oldX = column->width();
QCOMPARE(view.columnWidths()[columnNum], oldX);
grip->moveGrip(10);
QCOMPARE(view.columnWidths()[columnNum], (oldX + (reverse ? -10 : 10)));
}
示例10: currentWidget
void OutputWidget::scrollToIndex( const QModelIndex& idx )
{
QWidget* w = currentWidget();
if( !w )
return;
QAbstractItemView *view = dynamic_cast<QAbstractItemView*>(w);
view->scrollTo( idx );
}
示例11: QStyledItemDelegate
Palapeli::CollectionDelegate::CollectionDelegate (QObject* parent)
: QStyledItemDelegate(parent)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(parent);
if (view) {
view->setItemDelegate(this);
m_viewport = view->viewport();
}
}
示例12: forward
void TabPage::forward() {
// remember current scroll position
BrowseHistoryItem& item = history_.currentItem();
QAbstractItemView* childView = folderView_->childView();
item.setScrollPos(childView->verticalScrollBar()->value());
history_.forward();
chdir(history_.currentPath(), false);
}
示例13: Q_ASSERT
void StartPage::handle_selectionChanged()
{
QItemSelectionModel * sel_model = qobject_cast<QItemSelectionModel *>(sender());
Q_ASSERT(sel_model);
QAbstractItemView * area = area_of(sel_model->model());
Q_ASSERT(area);
QString button_name = area->property("open_button_name").toString();
QAbstractButton * button = findChild<QAbstractButton *>(button_name);
Q_ASSERT(button);
button->setEnabled( area->currentIndex().isValid() );
}
示例14: jumpToHistory
void TabPage::jumpToHistory(int index)
{
if(index >=0 && index < history_.size()) {
// remember current scroll position
BrowseHistoryItem& item = history_.currentItem();
QAbstractItemView* childView = folderView_->childView();
item.setScrollPos(childView->verticalScrollBar()->value());
history_.setCurrentIndex(index);
chdir(history_.currentPath(), false);
}
}
示例15: focusWidget
void BookmarksWidget::rename()
{
QWidget *w = focusWidget();
QAbstractItemView *view = qobject_cast<QAbstractItemView*>(w);
if (view) {
QModelIndexList indexes = view->selectionModel()->selectedIndexes();
if (indexes.isEmpty())
return;
QModelIndex index = indexes.first();
view->edit(index);
}
}