本文整理汇总了C++中QAbstractItemView::mapToGlobal方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::mapToGlobal方法的具体用法?C++ QAbstractItemView::mapToGlobal怎么用?C++ QAbstractItemView::mapToGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::mapToGlobal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
}
示例2: visualRect
/* FIXME make this less of a hack. */
QRect TestCalendarWidget::visualRect(QString const &item) const
{
TestWidgetsLog() << item << "my geometry is" << geometry();
QRect ret;
QAbstractItemView *view = q->findChild<QAbstractItemView*>();
QtUiTest::ListWidget *calendarView
= qtuitest_cast<QtUiTest::ListWidget*>(view);
if (!calendarView) {
return ret;
}
ret = calendarView->visualRect(item);
if (!ret.isNull()) {
ret.moveTopLeft( q->mapFromGlobal( view->mapToGlobal(ret.topLeft()) ) );
TestWidgetsLog() << item << "is a visible day at" << ret;
return ret;
}
QToolButton *yearButton = 0;
QToolButton *monthButton = 0;
QSpinBox *yearSpin = q->findChild<QSpinBox*>();
QMenu *monthMenu = 0;
QList<QToolButton*> blist = q->findChildren<QToolButton*>();
foreach(QToolButton *b, blist) {
if (!monthButton && (monthMenu = b->menu())) {
monthButton = b;
}
if (!b->menu()) {
yearButton = b;
}
}
TestWidgetsLog() << "monthButton" << monthButton << "yearButton" << yearButton;
TestWidgetsLog() << "item" << item << "monthMenu" << monthMenu;
if (yearButton && yearButton->isVisible() && yearButton->text() == item) {
QPoint p = q->mapFromGlobal( yearButton->mapToGlobal(QPoint(yearButton->width()+5, yearButton->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
TestWidgetsLog() << "click near yearbutton";
} else if (yearSpin && yearSpin->isVisible() && yearSpin->value() == item.toInt()) {
TestWidgetsLog() << "confirm spinbox";
QPoint p = q->mapFromGlobal( yearSpin->mapToGlobal(QPoint(yearSpin->width()+5, yearSpin->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
} else if (monthButton && monthButton->isVisible() && monthButton->text() == item) {
QPoint p = q->mapFromGlobal( monthButton->mapToGlobal(QPoint(-5, monthButton->height()/2)) );
ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
TestWidgetsLog() << "click near monthbutton";
} else if (monthMenu && monthMenu->isVisible()
&& qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)
&& qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->list().contains(item)) {
ret = qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->visualRect(item);
ret.moveTopLeft( q->mapFromGlobal( monthMenu->mapToGlobal(ret.topLeft()) ) );
TestWidgetsLog() << "click on monthmenu";
} else {
do {
QStringList items = list();
if (items.contains(item)) {
ret = QRect(-1, -1, 1, 1);
ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
break;
}
foreach (QString s, items) {
if (!s.startsWith(GetListRegExp)) continue;
QRegExp re(s.mid(GetListRegExp.length()));
if (re.exactMatch(item)) {
ret = QRect(-1, -1, 1, 1);
ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
break;
}
}
if (!ret.isNull()) break;
} while(0);
}
TestWidgetsLog() << "returning rect" << ret;
return ret;
}