mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 22:23:49 +08:00
e3c43198b9
使用了SpkSidebarTree子类实现对TreeWidget的特殊要求:不能取消选择,不能拖拽选择。 API调用接口暂时写死。API会获取 配置文件已添加但暂不使用。
32 lines
786 B
C++
32 lines
786 B
C++
|
|
#include <QMouseEvent>
|
|
#include "spksidebartree.h"
|
|
|
|
SpkUi::SpkSidebarTree::SpkSidebarTree(QWidget *parent) :
|
|
QTreeWidget(parent)
|
|
{
|
|
|
|
}
|
|
|
|
void SpkUi::SpkSidebarTree::mouseMoveEvent(QMouseEvent *e)
|
|
{
|
|
// This is solely for forcibly disabling the view to change selection when dragging on the view
|
|
// and probably the only reason why this class began its existence
|
|
if((e->buttons() & Qt::LeftButton))
|
|
setState(NoState);
|
|
else
|
|
QTreeWidget::mouseMoveEvent(e);
|
|
}
|
|
|
|
void SpkUi::SpkSidebarTree::mousePressEvent(QMouseEvent *e)
|
|
{
|
|
// Prevent anything being deselected
|
|
if(e->modifiers().testFlag(Qt::ControlModifier) && e->buttons().testFlag(Qt::LeftButton))
|
|
{
|
|
auto i = itemAt(e->pos());
|
|
if(i && i->isSelected())
|
|
return;
|
|
}
|
|
QTreeWidget::mousePressEvent(e);
|
|
}
|