Important: Please read the Qt Code of Conduct -

QGraphicsItem setPos() x(),y()=0

  • How to get x,y after addItem ?
    It seems first setPos() then can get Pos().
    If don not setPos(), pos() = (0,0).

    QGraphicsRectItem *GRI = scene->addRect(x, y, w, h, pen, brush);
    QGraphicsEllipseItem *GEI = scene->addEllipse(x, y, w, h, pen, brush);
    QGraphicsTextItem *GTI = scene->addText(text, font);
    QList<QGraphicsItem*> list_GI = scene->items(Qt::AscendingOrder);
    for(int i=0; i<list_GI.count(); i++){
        qDebug() <<>x() <<>y(); // 0 0
        qDebug() <<>width() <<>height(); // no these function

  • Lifetime Qt Champion


    Do you mean the QGraphicsItem::pos method ?

Log in to reply