123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "JListWidget.h"
- JListWidget::JListWidget(QWidget* parent /*= nullptr*/)
- : QListWidget(parent)
- {
- setDragDropMode(QAbstractItemView::InternalMove);
- setSelectionMode(QAbstractItemView::SingleSelection);
- setAcceptDrops(true);
- setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
- setStyleSheet(
- "QListWidget { background: #e6e6ed; border: 1px solid #ccc; }"
- "QListWidget::item { border-bottom: 1px solid #ddd; }"
- "QListWidget::item:hover { background: #e0e0ff; }"
- "QListWidget::item {"
- "border-bottom: 1px solid blue;"
- "padding: 5px;"
- "}"
- "QListWidget::item:last {"
- " border-bottom: none;"
- "}"
- );
- }
- void JListWidget::dragEnterEvent(QDragEnterEvent* event)
- {
- if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist"))
- {
- event->acceptProposedAction();
- }
- else
- {
- event->ignore();
- }
- }
- void JListWidget::dropEvent(QDropEvent* event)
- {
- if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist"))
- {
- QListWidget::dropEvent(event); // 调用默认的 dropEvent 来处理排序
- event->acceptProposedAction();
- // 发信号通知其他列表更新
- emit itemsReordered();
- }
- else
- {
- event->ignore();
- }
- }
|