本文整理汇总了C++中QAbstractItemView::indexAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::indexAt方法的具体用法?C++ QAbstractItemView::indexAt怎么用?C++ QAbstractItemView::indexAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::indexAt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool TooltipFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
QWidget *w = static_cast<QWidget *>(obj);
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QPoint pos = helpEvent->globalPos();
QString itemTooltip = w->toolTip();
QRect rect = w->rect();
// case of instrument tables inside a scrollarea viewport
if (w->objectName() == QLatin1String("qt_scrollarea_viewport"))
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
w = view;
QPoint position = helpEvent->pos();
QModelIndex index = view->indexAt(position);
if (!index.isValid())
{
return false;
}
rect = view->visualRect(index);
itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
}
switch (tooltipType_)
{
case TooltipType::NoTooltip:
QToolTip::hideText();
return true;
case TooltipType::StdTooltip:
QToolTip::showText(pos, itemTooltip, w, rect);
return true;
case TooltipType::CustomTooltip:
break;
default:
QToolTip::hideText();
emit updateTooltipRequest(itemTooltip);
return true;
}
}
return QObject::eventFilter(obj, event);
}
示例2: showRecentFoldersViewContextMenu
void StartMainPage::showRecentFoldersViewContextMenu(const QPoint& pos)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(sender());
KUrl url;
QModelIndex index = view->indexAt(pos);
if (index.isValid()) {
QVariant data = index.data(KFilePlacesModel::UrlRole);
url = data.toUrl();
}
// Create menu
QMenu menu(this);
bool fromRecentUrls = view == d->mRecentUrlsView;
QAction* addToPlacesAction = fromRecentUrls ? 0 : menu.addAction(KIcon("bookmark-new"), i18n("Add to Places"));
QAction* removeAction = menu.addAction(KIcon("edit-delete"), fromRecentUrls ? i18n("Forget this URL") : i18n("Forget this Folder"));
menu.addSeparator();
QAction* clearAction = menu.addAction(KIcon("edit-delete-all"), i18n("Forget All"));
if (!index.isValid()) {
if (addToPlacesAction) {
addToPlacesAction->setEnabled(false);
}
removeAction->setEnabled(false);
}
// Handle menu
QAction* action = menu.exec(view->mapToGlobal(pos));
if (!action) {
return;
}
if (action == addToPlacesAction) {
QString text = url.fileName();
if (text.isEmpty()) {
text = url.pathOrUrl();
}
d->mBookmarksModel->addPlace(text, url);
} else if (action == removeAction) {
view->model()->removeRow(index.row());
} else if (action == clearAction) {
view->model()->removeRows(0, view->model()->rowCount());
}
}
示例3: eventFilter
bool TableViewTooltip::eventFilter(QObject * obj, QEvent * event)
{
if (event->type() != QEvent::ToolTip) {
return false;
}
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view) {
return false;
}
QHelpEvent * helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid()) {
return false;
}
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
if (itemTooltip.isEmpty()) {
QToolTip::hideText();
return true;
}
QString itemText = view->model()->data(index).toString();
QFontMetrics fm(view->font());
int textIdentWidth =6;// fm.width('r'); // don't know how to calculate an ident for text in an item :-(
int itemTextWidth = fm.width(itemText) + textIdentWidth;
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if (itemTextWidth > rectWidth) {
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else {
QToolTip::hideText();
}
return true;
}
示例4: eventFilter
bool ColumnToolTip::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::ToolTip)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid())
return false;
QString itemText = view->model()->data(index).toString();
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
QFontMetrics fm(view->font());
int itemTextWidth = fm.width(itemText);
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if ((itemTextWidth > rectWidth) && !itemTooltip.isEmpty())
{
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else
{
QToolTip::hideText();
}
return true;
}
return false;
}