-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmylistwidget.cpp
More file actions
36 lines (33 loc) · 819 Bytes
/
mylistwidget.cpp
File metadata and controls
36 lines (33 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "mylistwidget.h"
#include<QMenu>
MyListWidget::MyListWidget(QWidget *parent):QListWidget(parent)
{
popMenu = new QMenu(this);
del=new QAction(tr("delete"), this);
popMenu->addAction(del);
connect(del,SIGNAL(triggered(bool)),this,SLOT(deleteItem()));
}
void MyListWidget::AddRightMenu(QAction *d)
{
if(d==Q_NULLPTR)
return;
popMenu->addAction(d);
}
void MyListWidget::contextMenuEvent(QContextMenuEvent *event)
{
QListWidgetItem *item=this->currentItem();
if(item==Q_NULLPTR)
{
return;
}
popMenu->exec(QCursor::pos()); // 菜单出现的位置为当前鼠标的位置
}
void MyListWidget::deleteItem()
{
QListWidgetItem *item=this->currentItem();
if(item!=Q_NULLPTR)
{
this->removeItemWidget(item);
delete item;
}
}