Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. [已解决]QDialog 中的坐标确定疑问
Forum Updated to NodeBB v4.3 + New Features

[已解决]QDialog 中的坐标确定疑问

Scheduled Pinned Locked Moved Chinese
4 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PhenixLan
    wrote on last edited by
    #1

    各位好,
    我是一名Qt的新手。现在我有一个mainwindow里面有qgraphicsScene, 在scene上面有很多elements,每个element都是一个button可以弹出qdialog。
    在qdialog中我依然layout一些elements。
    现在有一个问题,我需要在elements之间添加画线表示相连,现在我用的方法是qgraphicslineitem添加,elements的坐标用mapToGlobal确定,在mainwindow中没有问题,但是在qdialog中却怎么也画不出线。我发现mapToGlobal找到的qdialog中的坐标都是一个点。。这个问题已经困扰我很多天,希望知道解决方法的前辈能够给我些提示!!感谢! :)

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PhenixLan
      wrote on last edited by
      #2

      下面是我画线和找坐标的部分程序
      @
      QPoint hub_pos = fp_button->mapToGlobal(QPoint(fp_button->width()/2,fp_button->height()/2));
      //here we get the position of the current element//

      my_source = (*my_source_it);
      QPoint source_pos = my_source->mapToGlobal(QPoint(my_source->width()/2,my_source->height()/2));
      //here we get the position of the current source//

      QGraphicsLineItem* myItemline = new QGraphicsLineItem;
      QPen thinPen(Qt::black,1.2);
      myItemline->setPen(thinPen);
      myItemline->setLine(0,0,(source_pos.x()-hub_pos.x()),(source_pos.y()-hub_pos.y()));
      myItemline->setPos(hub_pos.x(),hub_pos.y());
      @

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PhenixLan
        wrote on last edited by
        #3

        刚刚解决了问题,
        我应该画线之前把scene画好,居然是顺序问题==

        麻烦大家啦:)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jiangcaiyang
          wrote on last edited by
          #4

          注释是英文的,还以为是拿老外的代码呢。

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved