本文整理汇总了C++中QAbstractItemView::currentIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::currentIndex方法的具体用法?C++ QAbstractItemView::currentIndex怎么用?C++ QAbstractItemView::currentIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::currentIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
示例2: handle_selectionChanged
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() );
}
示例3: eventFilter
bool BAutoCompletionHelper::eventFilter(QObject *object, QEvent *event)
{
if (event->type() != QEvent::KeyPress)
return false;
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return)
return false;
QAbstractItemView *popup = qobject_cast<QAbstractItemView *>(object);
if (!popup || !popup->isVisible())
return false;
popup->hide();
completerActivated(popup->currentIndex());
ke->ignore();
return true;
}
示例4: selectedColumns
void tst_QColumnView::selectedColumns()
{
ColumnView view;
QDirModel model;
view.setModel(&model);
view.resize(800,300);
view.show();
QModelIndex home = model.index(QDir::homePath());
view.setCurrentIndex(home);
QTest::qWait(ANIMATION_DELAY);
for (int i = 0; i < view.createdColumns.count(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
if (!column)
continue;
if (!column->rootIndex().isValid() || column->rootIndex() == home)
continue;
QTRY_VERIFY(column->currentIndex().isValid());
}
}
示例5: paint
void LedgerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
// never change the background of the cell the mouse is hovering over
opt.state &= ~QStyle::State_MouseOver;
// show the focus only on the detail column
opt.state &= ~QStyle::State_HasFocus;
if(index.column() == LedgerModel::DetailColumn) {
QAbstractItemView* view = qobject_cast< QAbstractItemView* >(parent());
if(view) {
if(view->currentIndex().row() == index.row()) {
opt.state |= QStyle::State_HasFocus;
}
}
}
painter->save();
// Background
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
// Do not paint text if the edit widget is shown
const LedgerView *view = qobject_cast<const LedgerView *>(opt.widget);
if (view && view->indexWidget(index)) {
painter->restore();
return;
}
const int margin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
const QRect textArea = QRect(opt.rect.x() + margin, opt.rect.y() + margin, opt.rect.width() - 2 * margin, opt.rect.height() - 2 * margin);
QStringList lines;
if(index.column() == LedgerModel::DetailColumn) {
lines << index.model()->data(index, LedgerModel::PayeeNameRole).toString();
lines << index.model()->data(index, LedgerModel::CounterAccountRole).toString();
lines << index.model()->data(index, LedgerModel::SingleLineMemoRole).toString();
lines.removeAll(QString());
}
const bool erroneous = index.model()->data(index, LedgerModel::ErroneousRole).toBool();
const bool selected = opt.state & QStyle::State_Selected;
// draw the text items
if(!opt.text.isEmpty() || !lines.isEmpty()) {
// check if it is a scheduled transaction and display it as inactive
if(!index.model()->data(index, LedgerModel::ScheduleIdRole).toString().isEmpty()) {
opt.state &= ~QStyle::State_Enabled;
}
QPalette::ColorGroup cg = (opt.state & QStyle::State_Enabled)
? QPalette::Normal : QPalette::Disabled;
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) {
cg = QPalette::Inactive;
}
if (opt.state & QStyle::State_Selected) {
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
} else {
painter->setPen(opt.palette.color(cg, QPalette::Text));
}
if (opt.state & QStyle::State_Editing) {
painter->setPen(opt.palette.color(cg, QPalette::Text));
painter->drawRect(textArea.adjusted(0, 0, -1, -1));
}
// Don't play with the color if it's selected
// otherwise switch the color if the transaction has errors
if(erroneous && !selected) {
painter->setPen(m_erroneousColor);
}
// collect data for the various colums
if(index.column() == LedgerModel::DetailColumn) {
for(int i = 0; i < lines.count(); ++i) {
painter->drawText(textArea.adjusted(0, (opt.fontMetrics.lineSpacing() + 5) * i, 0, 0), opt.displayAlignment, lines[i]);
}
} else {
painter->drawText(textArea, opt.displayAlignment, opt.text);
}
}
// draw the focus rect
if(opt.state & QStyle::State_HasFocus) {
QStyleOptionFocusRect o;
o.QStyleOption::operator=(opt);
o.rect = style->proxy()->subElementRect(QStyle::SE_ItemViewItemFocusRect, &opt, opt.widget);
o.state |= QStyle::State_KeyboardFocusChange;
o.state |= QStyle::State_Item;
QPalette::ColorGroup cg = (opt.state & QStyle::State_Enabled)
? QPalette::Normal : QPalette::Disabled;
o.backgroundColor = opt.palette.color(cg, (opt.state & QStyle::State_Selected)
? QPalette::Highlight : QPalette::Window);
style->proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter, opt.widget);
//.........这里部分代码省略.........