Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Question about Coordinates in QDialog
Forum Updated to NodeBB v4.3 + New Features

[solved]Question about Coordinates in QDialog

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k 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

    Hello,
    I'm new in Qt. And there is a problem I worked on several days and got no result yet.
    I have a mainwindow which has a QGraphicsView and QGraphicsScene for laying out many elements(buttons). Each button on my scene can show a new QDialog which also use QGraphicsScene laying out elements.

    Now I have to add QGraphicsLineItem on the scene to show the connections between the elements. It works fine with mapToGlobal on the mainwindow, but with the new QDialog there is noline show up, always only a dot!! I've tried mapToParent and also not right, please someone help me with this!! Thanks:)

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

      here is the code I use to draw the line
      @ 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

        I've just solved my problem.
        It's because I haven't set the Scene ready before the LineItem.
        So silly mistake. Thanks for your concern:)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Great that you could solve your problem !

          Can you also update the thread title to solved so that others know it's all good.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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