Important: Please read the Qt Code of Conduct -

how to create a signal clicked() for a class that inherited form QGraphicsPolygonItem(parent)??

  • hi ,i have a class that inherited from QGraphicsPolygonItem,how can i created signal clicked for my object.

    class DiagramItem : public QGraphicsPolygonItem

    i added QWidget class to DiagramItem class,but i has errors,i.e. i use

    class DiagramItem : public QGraphicsPolygonItem,QWidget

    the errors:

    F:\Users\ROOT\Documents\Qt\diagramscene\arrow.cpp:106: error: request for member 'pos' is ambiguous
         QLineF centerLine(myStartItem->pos(), myEndItem->pos());

    more info method pos has overlap!!!please help me
    this is part my source that i used method pos :

        QLineF centerLine(myStartItem->pos(), myEndItem->pos());
        QPolygonF endPolygon = myEndItem->polygon();
        QPointF p1 = endPolygon.first() + myEndItem->pos();
        QPointF p2;
        QPointF intersectPoint;
        QLineF polyLine;

  • i too override pos function but it has erorrs:
    the a part of source

    void DiagramItem::pos(){

    the errors??

     F:\Users\ROOT\Documents\Qt\diagramscene\arrow.cpp:106: error: invalid use of void expression
       QLineF centerLine(myStartItem->pos(), myEndItem->pos());
    F:\Users\ROOT\Documents\Qt\diagramscene\arrow.cpp:108: error: no match for 'operator+' (operand types are 'QPointF' and 'void')
       QPointF p1 = endPolygon.first() + myEndItem->pos();

  • Lifetime Qt Champion


    Your pos function return type is void hence the errors.

    In your case. don't inherit from QWidget but from QObject, and it should also be the first class in the inheritance list.

Log in to reply