| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhenyu Wang <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "klistview.h" |
| 24 |
#include <QDebug> |
| 25 |
namespace kdk |
| 26 |
{ |
| 27 |
|
| 28 |
class KListViewPrivate : public QObject |
| 29 |
{ |
| 30 |
Q_OBJECT |
| 31 |
Q_DECLARE_PUBLIC(KListView) |
| 32 |
public: |
| 33 |
KListViewPrivate(KListView *parent); |
| 34 |
|
| 35 |
private: |
| 36 |
KListView *q_ptr; |
| 37 |
}; |
| 38 |
|
| 39 |
KListViewPrivate::KListViewPrivate(KListView *parent) |
| 40 |
: q_ptr(parent) |
| 41 |
{ |
| 42 |
Q_Q(KListView); |
| 43 |
setParent(parent); |
| 44 |
} |
| 45 |
|
| 46 |
KListView::KListView(QWidget *parent) |
| 47 |
: QListView(parent) |
| 48 |
, d_ptr(new KListViewPrivate(this)) |
| 49 |
{ |
| 50 |
Q_D(KListView); |
| 51 |
} |
| 52 |
|
| 53 |
void KListView::mousePressEvent(QMouseEvent *event) |
| 54 |
{ |
| 55 |
Q_D(KListView); |
| 56 |
QPoint p = event->pos(); // 获取点击坐标 |
| 57 |
QModelIndex index = indexAt(p); // 点击位置是否为空 |
| 58 |
if (!index.isValid()) { |
| 59 |
setCurrentIndex(QModelIndex()); // 实现点空白处取消选择 |
| 60 |
} |
| 61 |
QListView::mousePressEvent(event); |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
#include "klistview.moc" |
| 67 |
#include "moc_klistview.cpp" |