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. how to create a signal clicked() for a class that inherited form QGraphicsPolygonItem(parent)??
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k Views 2 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.
  • stackprogramerS Offline
    stackprogramerS Offline
    stackprogramer
    wrote on last edited by stackprogramer
    #1

    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;
    
    1 Reply Last reply
    0
    • stackprogramerS Offline
      stackprogramerS Offline
      stackprogramer
      wrote on last edited by
      #2

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

      void DiagramItem::pos(){
          QGraphicsPolygonItem::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();
                                         ^                            
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        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.

        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
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved