Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [Solved] Adding text inside QGraphicsEllipseItem

    General and Desktop
    2
    3
    3817
    Loading More Posts
    • 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.
    • A
      amban last edited by

      Hi All,
      I have the following code which is generating 5 ellipses in a horizontal line :
      @
      void Widget::createItem( int x, QGraphicsScene *scene )
      {
      QRect rect(x+105, 50, 145, 100);
      ellipseItem = new QGraphicsEllipseItem( rect, 0, scene );

      QBrush brush;
      QPixmap pix(250,250);
      pix.fill(Qt::transparent);
      QPainter paint(&pix);
      paint.setPen("black");
      paint.setOpacity(0.75);
      paint.drawText(rect, Qt::AlignCenter ,"OK");
      brush.setTexture(pix);
      ellipseItem->setBrush(brush);
      

      }
      @

      Values of x = 0, 200, 400, 600, 800

      For the above code, the first instance works perfect i.e. "OK" is displayed in the center of the 1st QGraphicsEllipseItem but not for the others....what am i doing wrong?

      Please help.

      1 Reply Last reply Reply Quote 0
      • A
        amban last edited by

        No reply !!! Can anyone help me by sharing ideas on how to implement this - adding text inside QGraphicsEllipseItem.

        1 Reply Last reply Reply Quote 0
        • L
          ludde last edited by

          Not sure what you are trying to accomplish, but if you want to create a graphics item that is displayed as an ellipse with text in it, this it definitely not the way to do it.

          You have to make that graphics item draw the text as well, you cannot just do that yourself when you create the item. To do that, you could subclass QGraphicsEllipseItem, reimplement the paint event, and paint the text in there (before or after you call the QGraphicsEllipseItem paint event).

          1 Reply Last reply Reply Quote 0
          • First post
            Last post