一、效果预览
二、代码
cpp文件
void MainWindow::Rightclicklistview()
{
TotalRightclick =new QMenu(this);
AddDevice = new QMenu(this);
upDevice = new QAction(this);
DownDevice = new QAction(this);
Delete = new QAction(this);
EditDevice = new QAction(this);
DeviceIS6201A =new QMenu(this);
DeviceIS6202A = new QMenu(this);
DeviceIS6203A = new QMenu(this);
DeviceIS6201A_IIC = new QAction(this);
DeviceIS6201A_PMBV1 = new QAction(this);
DeviceIS6201A_PMBV2= new QAction(this);
QIcon iconadd = QIcon(":/Res/tools/add.png");
QIcon iconUp = QIcon(":/Res/tools/moveup.png");
QIcon iconDown = QIcon(":/Res/tools/movedown.png");
QIcon iconDelete = QIcon(":/Res/tools/delete.png");
QIcon iconEdit = QIcon(":/Res/tools/paste.png");
QIcon iconUser = QIcon(":/Res/tools/user.png");
QIcon iconChip = QIcon(":/Res/tools/xinpian.png");
AddDevice = TotalRightclick->addMenu(iconadd," Add Device");
upDevice = TotalRightclick->addAction(iconUp," Move Up Device");
DownDevice = TotalRightclick->addAction(iconDown," Move Down Device");
Delete = TotalRightclick->addAction(iconDelete," Delete Device");
EditDevice = TotalRightclick->addAction(iconEdit," Edit Device");
DeviceIS6201A = AddDevice->addMenu(iconUser," IS6201A");
DeviceIS6202A = AddDevice->addMenu(iconUser," IS6202A");
DeviceIS6203A = AddDevice->addMenu(iconUser," IS6203A");
DeviceIS6201A_IIC = DeviceIS6201A->addAction(iconChip, " IS6201A_IIC");
DeviceIS6201A_PMBV1 = DeviceIS6201A->addAction(iconChip," IS6201A_PMBV1");
DeviceIS6201A_PMBV2= DeviceIS6201A->addAction(iconChip, " IS6201A_PMBV2");
connect( upDevice, &QAction::triggered, [=]()
{
qDebug()<<"I'm upDevice";
});
connect( DownDevice, &QAction::triggered, [=]()
{
qDebug()<<"I'm DownDevice";
});
connect( Delete, &QAction::triggered, [=]()
{
}
qDebug()<<"I'm DeleteAction";
});
connect( EditDevice, &QAction::triggered, [=]()
{
qDebug()<<"I'm btnSecondAction";
});
connect( DeviceIS6201A_PMBV1, &QAction::triggered, [=]()
{
qDebug()<<"I'm DeviceIS6201A_PMBV1";
});
connect( DeviceIS6201A_PMBV2, &QAction::triggered, [=]()
{
qDebug()<<"I'm DeviceIS6201A_PMBV2";
});
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->listView,&QLabel::customContextMenuRequested,[=](const QPoint &pos)
{
qDebug()<<pos;
TotalRightclick->exec(QCursor::pos());
});
}
- 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
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
h文件
private:
void Rightclicklistview();
QAction * upDevice;
QAction * DownDevice;
QAction * Delete;
QAction * EditDevice;
QAction * DeviceIS6201A_IIC;
QAction * DeviceIS6201A_PMBV1;
QAction * DeviceIS6201A_PMBV2;
QMenu * TotalRightclick;
QMenu * AddDevice;
QMenu * DeviceIS6201A;
QMenu * DeviceIS6202A;
QMenu * DeviceIS6203A;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
参考二
参考三