目标:

在Widget中添加 tab ,在 tab 中加 label ,在label 中加载图片,要获取图片中某些物体相对于图片左上角的像素坐标。

 

本来用的 e->pos().x()-ui->label->x();

               e->pos().y()-ui->label->y();

 

却发现不行!!label   的左上角坐标是相对  tab  可编辑区左上角的。而 tab  又很麻烦。看下图:

QT5.11版本中 tab 中的 label 的位置

label 是相对于  的位置的。

所以要使   label   中图片左上角为(0,0)就要用。

x=e->pos().x()-ui->tabWidget->x()-ui->label->x();

y=e->pos().y()-ui->tabWidget->y()-ui->label->y()-ui->tabWidget->tabBar()->height();

相关文章:

  • 2021-05-10
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2021-10-15
猜你喜欢
  • 2022-01-22
  • 2022-12-23
  • 2021-04-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案