本文整理汇总了C++中QAbstractItemView::setCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::setCurrentIndex方法的具体用法?C++ QAbstractItemView::setCurrentIndex怎么用?C++ QAbstractItemView::setCurrentIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::setCurrentIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showPopup
void DDateEdit::showPopup()
{
if ( d->readOnly )
{
return;
}
QRect desk = KGlobalSettings::desktopGeometry( this );
QPoint popupPoint = mapToGlobal( QPoint( 0,0 ) );
int dateFrameHeight = d->popup->sizeHint().height();
if ( popupPoint.y() + height() + dateFrameHeight > desk.bottom() )
{
popupPoint.setY( popupPoint.y() - dateFrameHeight );
}
else
{
popupPoint.setY( popupPoint.y() + height() );
}
int dateFrameWidth = d->popup->sizeHint().width();
if ( popupPoint.x() + dateFrameWidth > desk.right() )
{
popupPoint.setX( desk.right() - dateFrameWidth );
}
if ( popupPoint.x() < desk.left() )
{
popupPoint.setX( desk.left() );
}
if ( popupPoint.y() < desk.top() )
{
popupPoint.setY( desk.top() );
}
if ( d->date.isValid() )
{
d->popup->setDate( d->date );
}
else
{
d->popup->setDate( QDate::currentDate() );
}
d->popup->popup( popupPoint );
// The combo box is now shown pressed. Make it show not pressed again
// by causing its (invisible) list box to emit a 'selected' signal.
// First, ensure that the list box contains the date currently displayed.
QDate date = parseDate();
assignDate( date );
updateView();
// Now, simulate an Enter to unpress it
QAbstractItemView* lb = view();
if (lb)
{
lb->setCurrentIndex( lb->model()->index( 0, 0 ) );
QKeyEvent* keyEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QApplication::postEvent(lb, keyEvent);
}
}