的選擇您好所有 我從QTreeView則繼承類,我實現簡單的(空)mousePressEvent功能
但每當我試圖做到這一點,在QTreeView則該項目的選擇是殘疾人,當我刪除這個功能一切正常工作
什麼我想在這裏失蹤?
這裏是代碼:QTreeView則mousePressEvent實施防止物品
void MyTreeWidget::mousePressEvent(QMouseEvent *event)
{
QModelIndex index = this->indexAt(event->pos());
QAbstractItemModel *model = this->model();
QMap<int, QVariant> ItemData = model->itemData(index);
QMap<int, QVariant>::const_iterator i = ItemData.constBegin();
while (i != ItemData.constEnd()) {
QString k = QString::number(i.key());
QString v = i.value().toString();
++i;
}
if (event->button() == Qt::LeftButton) {
QByteArray itemData ;
QString urlTo;
itemData.append(urlTo);
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/x-dnditemdata", itemData);
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
if (dropAction == Qt::MoveAction)
{
UT::getInstance()->LogToFile("dropAction");
}
}
QTreeView::mousePressEvent(event);
}
找到答案在這裏: http://www.qtcentre.org/threads/34915-Drag-and-drop-QTreeWidgetItem-to-QTableWidget – user63898 2010-10-27 15:29:09