Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adjust the size of QGraphicstextItem
Qt 6.12 LTS is out! See what's new in the release blog

Adjust the size of QGraphicstextItem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.2k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    hi, some help me,how can we adjust the size of QGraphistextitem...i reimplemented the QGraphicsTextitem and when i adjusted the bounding rect size..full text is not visibling ...please tell me how to adjust the size of that text to fix in rectitem...

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      this is the code i tried

      @
      class GraphicsTextItemSized : public QGraphicsTextItem
      {
      public:
      GraphicsTextItemSized(QGraphicsItem* parent = 0);
      GraphicsTextItemSized(const QString& text, QGraphicsItem* parent = 0);

      QRectF boundingRect() const;
      QString str;
      QRectF adjustedrect;
      
       void forcedsize(qreal x1,qreal y1,qreal x2,qreal y2);
      

      };
      @

      @
      #include "graphicstextitemsized.h"
      #include <QtCore>
      #include <QtGui>
      #include <QGraphicsTextItem>

      GraphicsTextItemSized::GraphicsTextItemSized(const QString &text, QGraphicsItem *parent):QGraphicsTextItem(text,parent)
      {
      setPlainText( text);
      }
      QRectF GraphicsTextItemSized::boundingRect() const
      {
      return (adjustedrect);
      }

      void GraphicsTextItemSized::forcedsize(qreal x1,qreal y1,qreal x2,qreal y2)
      {
      adjustedrect.setCoords(0,0,x2-x1,y2-y1);
      }

      @
      @
      QGraphicsRectItem *rect = new QGraphicsRectItem(0,0,0,0);
      GraphicsTextItemSized *tes = new GraphicsTextItemSized(QString("vcc"),rect);
      tes->forcedsize(0,0,10,10);
      tes->setPos(10.0,10.0);
      scene->addItem(rect);
      @

      1 Reply Last reply
      0

      • Login

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