当前位置: 首页>>代码示例>>C++>>正文


C++ QAbstractItemView::indexAt方法代码示例

本文整理汇总了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);
}
开发者ID:LI-COR,项目名称:eddypro-gui,代码行数:50,代码来源:tooltipfilter.cpp

示例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());
    }
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例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;    
}
开发者ID:biophor,项目名称:AdBook,代码行数:38,代码来源:TableViewTooltip.cpp

示例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;
}
开发者ID:helkatz,项目名称:LogViewer,代码行数:36,代码来源:ColumnToolTip.cpp


注:本文中的QAbstractItemView::indexAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。