QAbstractItemView: Make it easier to drop above and below items
Before this patch a very accurate drop position below or above an index was needed. Therefore it was not that easy to do. This patch increases the above/below area to be about 18% of the item (still leaving the most space for the item). An average user will likely be 2-3x faster with dropping below or above (while not losing much when dropping on items). [ChangeLog][QtWidgets][ItemViews] Made it easier to drop above and below items. Change-Id: I47f0f80c76878c17ebf3f93d0a0cc82755971c2a Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
03c3ba1815
commit
a1c985c10b
@ -2194,7 +2194,7 @@ QAbstractItemViewPrivate::position(const QPoint &pos, const QRect &rect, const Q
|
||||
{
|
||||
QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport;
|
||||
if (!overwrite) {
|
||||
const int margin = 2;
|
||||
const int margin = qBound(2, qRound(qreal(rect.height()) / 5.5), 12);
|
||||
if (pos.y() - rect.top() < margin) {
|
||||
r = QAbstractItemView::AboveItem;
|
||||
} else if (rect.bottom() - pos.y() < margin) {
|
||||
|
@ -95,6 +95,18 @@ public:
|
||||
item5sl.append("Approver");
|
||||
/* QTreeWidgetItem *item4 =*/ new QTreeWidgetItem(item4, item5sl);
|
||||
|
||||
treeWidget->setDragEnabled(true);
|
||||
treeWidget->viewport()->setAcceptDrops(true);
|
||||
treeWidget->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
for (int u = 0; u < 12; ++u) {
|
||||
const QString username = QString("Anonymous User %1").arg(u + 1);
|
||||
QStringList info;
|
||||
info << username << username << QString::number(u + 1) << QStringLiteral("Test user");
|
||||
new QTreeWidgetItem(item4, info);
|
||||
}
|
||||
|
||||
treeWidget->expandAll();
|
||||
treeWidget->setColumnCount(item2sl.size());
|
||||
QStringList itemInfo("First Name");
|
||||
itemInfo.append("Last Name");
|
||||
@ -133,6 +145,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
ExampleDlg d;
|
||||
d.resize(d.sizeHint() * 3);
|
||||
d.show();
|
||||
app.exec();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user