二级menu菜单的显示:
//menu
void MainWindow::menuChoice()
{
getCurrentPosition();
setHeighLight(row,col);
menu.addAction(QIcon(":/close.png"),QString::fromLocal8Bit("缺牙"),this,SLOT(loseTooth()));
menu.addAction(QIcon(":/cut .png"),QString::fromLocal8Bit("片切"),this,SLOT(piecesCut()));
menu.addAction(QIcon(":/baya.png"),QString::fromLocal8Bit("拔牙"),this,SLOT(cutTooth()));
//二级菜单
addFile = new QMenu(QString::fromLocal8Bit("加附件"));
rectAction = new QAction(QIcon(":/file1.png"),QString::fromLocal8Bit("加矩形"),this);
ecllipseAction = new QAction(QIcon(":/file2.png"),QString::fromLocal8Bit("加椭圆"),this);
polygonAction = new QAction(QIcon(":/file3.png"),QString::fromLocal8Bit("自定义"),this);
addFile->setIcon(QIcon(":/add.png"));
addFile->addAction(rectAction);
addFile->addAction(ecllipseAction);
addFile->addAction(polygonAction);
menu.addMenu(addFile);
removeFile = new QMenu(QString::fromLocal8Bit("除附件"));
rectRemoveAction = new QAction(QIcon(":/file1.png"),QString::fromLocal8Bit("除矩形"),this);
ecllipseRemoveAction = new QAction(QIcon(":/file2.png"),QString::fromLocal8Bit("除椭圆"),this);
polygonRemoveAction = new QAction(QIcon(":/file3.png"),QString::fromLocal8Bit("自定义"),this);
removeFile->setIcon(QIcon(":/delete.png"));
removeFile->addAction(rectRemoveAction);
removeFile->addAction(ecllipseRemoveAction);
removeFile->addAction(polygonRemoveAction);
menu.addMenu(removeFile);
judgeEnabled();
connect(rectAction,SIGNAL(triggered()),this,SLOT(drawRect()));
connect(rectRemoveAction,SIGNAL(triggered()),this,SLOT(removeRect()));
connect(ecllipseAction,SIGNAL(triggered()),this,SLOT(drawEllipse()));
connect(ecllipseRemoveAction,SIGNAL(triggered()),this,SLOT(removeEllipse()));
connect(polygonAction,SIGNAL(triggered()),this,SLOT(drawPolygon()));
connect(polygonRemoveAction,SIGNAL(triggered()),this,SLOT(removePolygon()));
menu.addAction(QIcon(":/left.png"),QString::fromLocal8Bit("左移"),this,SLOT(leftRemove()));
menu.addAction(QIcon(":/right.png"),QString::fromLocal8Bit("右移"),this,SLOT(rightRemove()));
menu.addAction(QIcon(":/chexiao.png"),QString::fromLocal8Bit("撤销"),this,SLOT(undo()));
//获取当前鼠标位置
menu.exec(QCursor::pos());
}
//单列高亮
//tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
tableWidget->setStyleSheet("selection-background-color:lightgreen");
1.点击时出现的十字高亮设置:
//设置十字高亮
void MainWindow::setHeighLight(int width,int height){
QItemSelectionModel *model = tableWidget->selectionModel();
QModelIndex topLeft = tableWidget->model()->index(width, height, QModelIndex());
QModelIndex bottomRight = tableWidget->model()->index(width, height, QModelIndex());
QItemSelection selection;
selection.select(topLeft,bottomRight);
model->select(selection,QItemSelectionModel::Select
|QItemSelectionModel::Rows|QItemSelectionModel::Columns);
//tableWidget->setSelectionModel(model);
}