[已解决]QDialog 中的坐标确定疑问
-
各位好,
我是一名Qt的新手。现在我有一个mainwindow里面有qgraphicsScene, 在scene上面有很多elements,每个element都是一个button可以弹出qdialog。
在qdialog中我依然layout一些elements。
现在有一个问题,我需要在elements之间添加画线表示相连,现在我用的方法是qgraphicslineitem添加,elements的坐标用mapToGlobal确定,在mainwindow中没有问题,但是在qdialog中却怎么也画不出线。我发现mapToGlobal找到的qdialog中的坐标都是一个点。。这个问题已经困扰我很多天,希望知道解决方法的前辈能够给我些提示!!感谢! :) -
下面是我画线和找坐标的部分程序
@
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());
@ -
刚刚解决了问题,
我应该画线之前把scene画好,居然是顺序问题==麻烦大家啦:)
-
注释是英文的,还以为是拿老外的代码呢。