Important: Please read the Qt Code of Conduct -

[solved]Question about Coordinates in QDialog

  • 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:)

  • 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);


  • 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:)

  • Lifetime Qt Champion


    Great that you could solve your problem !

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

Log in to reply