QTableWidget十字高亮设置

二级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);
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值