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. Diagram Scene Example ::paint and ::setPolygon
Forum Updated to NodeBB v4.3 + New Features

Diagram Scene Example ::paint and ::setPolygon

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 1 Posters 361 Views
  • 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.
  • M Offline
    M Offline
    markwang
    wrote on last edited by
    #1

    as the example Diagram Scene Example:
    diagramitem.cpp

            setPolygon(myPolygon);
            setFlag(QGraphicsItem::ItemIsMovable, true);
            setFlag(QGraphicsItem::ItemIsSelectable, true);
            setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    

    item can select, move;
    but when i change it a little:
    to:

    //setPolygon(myPolygon);
               setFlag(QGraphicsItem::ItemIsMovable, true);
               setFlag(QGraphicsItem::ItemIsSelectable, true);
               setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    
    QRectF  DiagramItem::boundingRect() const
    {
        qreal penWidth = 1;
        switch (myDiagramType) {
            case StartEnd:
                return QRectF(0 - penWidth / 2,0 - penWidth / 2,
                   200 + penWidth, 200 + penWidth);
                break;
            case Conditional:
                return QRectF(-100 - penWidth / 2, -100 - penWidth / 2,
                               200 + penWidth, 200 + penWidth);
            case Step:
                return QRectF(-100 - penWidth / 2, -100 - penWidth / 2,
                           200 + penWidth, 200 + penWidth);
            case Io:
                return QRectF(-120 - penWidth / 2, -80 - penWidth / 2,
                       240 + penWidth, 160 + penWidth);
        }
    
    }
    
    void  DiagramItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
    {
        painter->drawPolygon(myPolygon );
    }
    

    item can show but can be selected and moved, Arrow can not work also;

    1 Reply Last reply
    0
    • M Offline
      M Offline
      markwang
      wrote on last edited by
      #2

      11e40ad0-85a2-435a-b859-1e9f62171888-image.png alt text

      1 Reply Last reply
      0
      • M Offline
        M Offline
        markwang
        wrote on last edited by
        #3

        Reimplement mouseMoveEvent and mousePressEvent; set breakPiont . finded that it is not executed.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          markwang
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • M Offline
            M Offline
            markwang
            wrote on last edited by
            #5

            ha, diagramitem Inherit QGraphicsPolygonItem , change it to inherit QGraphicsItem.

            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