2017-10-06 77 views
0

我的Qt版本是5.5.1(Linux),由于某些原因,我无法升级它。QStandardItem全球位置

我有QTableView(从QWidget继承),并且这个QTableView有模型QStandardItemModel与一些QStandardItem。问题是:在这种情况下如何获得QStandarditem全球协调?

UI文件

QWidget *MY_QWidget; 
MY_QTableView *MY_QTableView; 
MY_QWidget = new QWidget(); 
MY_QTableView = new QTableView(MY_QWidget); 

.h文件

QStandardItemModel * MY_QStandardItemModel; 

CPP文件

MY_QStandardItemModel = new QStandardItemModel(); 
ui->MY_QTableView->setModel(MY_QStandardItemModel); 

QStandardItem *MY_QStandardItem; 
MY_QStandardItem = new QStandardItem(tr("some text")); 
MY_QStandardItemModel->setItem(0,0,MY_QStandardItem);// <- Global position of this item                     

回答

1

对于获得的QStandardItem局部位置可以使用QAbstractItemView::visualRect

QModelIndex index = MY_QStandardItemModel->indexFromItem(MY_QStandardItem); 
QRect rect = MY_QTableView->visualRect(index); 
Qpoint localPoint = rect.topLeft(); // <- the local position 

并为获得全球的地位,你可以使用QWidget::mapToGlobal

Qpoint globalPosition MY_QTableView->mapToGlobal(localPoint); // <- the global position