Hmmm, that might be embarrissing for me (after all I'm QT beginner) but I get compile errors when I just copy it.
{
QModelIndexList indexes = selectedIndexes();
if (indexes.count() > 0) {
// setup pixmap
QRect rect
= visualRect
(indexes.
at(0));
QList<QRect> rects;
for (int i = 0; i < indexes.count(); ++i) {
rects.append(visualRect(indexes.at(i)));
rect |= rects.at(i);
}
rect = rect.intersect(d->viewport->rect());
pixmap.fill(palette().base().color());
option.
state |
= QStyle::State_Selected;
for (int j = 0; j < indexes.count(); ++j) {
option.
rect = QRect(rects.
at(j
).
topLeft() - rect.
topLeft(),
rects.at(j).size());
itemDelegate()->paint(&painter, option, indexes.at(j));
}
painter.end();
// create drag object
drag->setPixmap(pixmap);
drag->setMimeData(model()->mimeData(indexes));
drag
->setHotSpot
(d
->viewport
->mapFromGlobal
(QCursor::pos()) - rect.
topLeft());
if (drag->start(supportedActions) == Qt::MoveAction)
d->removeSelectedRows();
}
}
void QAbstractItemView::startDrag(Qt::DropActions supportedActions)
{
Q_D(QAbstractItemView);
QModelIndexList indexes = selectedIndexes();
if (indexes.count() > 0) {
// setup pixmap
QRect rect = visualRect(indexes.at(0));
QList<QRect> rects;
for (int i = 0; i < indexes.count(); ++i) {
rects.append(visualRect(indexes.at(i)));
rect |= rects.at(i);
}
rect = rect.intersect(d->viewport->rect());
QPixmap pixmap(rect.size());
pixmap.fill(palette().base().color());
QPainter painter(&pixmap);
QStyleOptionViewItem option = viewOptions();
option.state |= QStyle::State_Selected;
for (int j = 0; j < indexes.count(); ++j) {
option.rect = QRect(rects.at(j).topLeft() - rect.topLeft(),
rects.at(j).size());
itemDelegate()->paint(&painter, option, indexes.at(j));
}
painter.end();
// create drag object
QDrag *drag = new QDrag(this);
drag->setPixmap(pixmap);
drag->setMimeData(model()->mimeData(indexes));
drag->setHotSpot(d->viewport->mapFromGlobal(QCursor::pos()) - rect.topLeft());
if (drag->start(supportedActions) == Qt::MoveAction)
d->removeSelectedRows();
}
}
To copy to clipboard, switch view to plain text mode
../../../qt/qt-4.1.4/include/QtGui/qtableview.h: In member function `virtual
void MyTableView::startDrag(QFlags<Qt::DropAction>)':
../../../qt/qt-4.1.4/include/QtGui/qtableview.h:134: `QTableViewPrivate*
QTableView::d_func()' is private
mytableview.cpp:43: within this context
mytableview.cpp:43: cannot convert `QTableViewPrivate*' to `
QAbstractItemViewPrivate* const' in initialization
mytableview.cpp:53: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
mytableview.cpp:69: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
mytableview.cpp:71: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
make: *** [mytableview.o] Error 1
../../../qt/qt-4.1.4/include/QtGui/qtableview.h: In member function `virtual
void MyTableView::startDrag(QFlags<Qt::DropAction>)':
../../../qt/qt-4.1.4/include/QtGui/qtableview.h:134: `QTableViewPrivate*
QTableView::d_func()' is private
mytableview.cpp:43: within this context
mytableview.cpp:43: cannot convert `QTableViewPrivate*' to `
QAbstractItemViewPrivate* const' in initialization
mytableview.cpp:53: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
mytableview.cpp:69: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
mytableview.cpp:71: invalid use of undefined type `struct
QAbstractItemViewPrivate'
../../../qt/qt-4.1.4/include/QtGui/qabstractitemview.h:41: forward declaration
of `struct QAbstractItemViewPrivate'
make: *** [mytableview.o] Error 1
To copy to clipboard, switch view to plain text mode
Bookmarks