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. [Solved] outline on a QGraphicsTextItem
Qt 6.11 is out! See what's new in the release blog

[Solved] outline on a QGraphicsTextItem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 11.8k 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.
  • E Offline
    E Offline
    eric_vi
    wrote on last edited by
    #1

    Hello,

    i am using QGraphicsTextItem on a QGraphicsScene, i would like to have my QGraphicsTextItem as outline text, i cannot find a way to achieve that... Anyone has any idea how to do it.

    Thank you for your help

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on last edited by
      #2

      Without re-implementing the paint method?! hum, I'm afraid not...

      However, you can you use "QGraphicsSimpleTextItem":http://doc.trolltech.com/4.6/qgraphicssimpletextitem.html?
      If so, you can use setPen to set the outline color and setBrush to transparent.

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eric_vi
        wrote on last edited by
        #3

        hello thank you for your answer...

        well QGrahicsSimpleTextItem, is not rich text and does not let me reedit the text.

        So reimplementing the paint method is what i am trying to figure out but unfortunately i cannot see how to grab the text to addit to a QPainterPath (if this mecanism can work!)

        1 Reply Last reply
        0
        • E Offline
          E Offline
          eric_vi
          wrote on last edited by
          #4

          i have been helped to solve that, it works, you need to have the appropriate QCharFormat setup to the QTextCursor of your QGraphicstextitem

          1 Reply Last reply
          0
          • D Offline
            D Offline
            danilocesar
            wrote on last edited by
            #5

            Can you post the code here?

            <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
            Software Engineer

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tbscope
              wrote on last edited by
              #6

              Here's the code.
              Context:
              A widget is created in designer with a QGraphicsView.
              A QGraphicsScene pointer is defined as a private member of the widget.
              A QTextDocument is defined as a private member of the widget (although that is not necessary, the document of the QGraphicsTextItem can be used too)
              A QGraphicsTextItem is defined as a private member of the widget.

              @
              ui->setupUi(this);

              scene = new QGraphicsScene(ui->graphicsView);
              ui->graphicsView->setScene(scene);

              document = new QTextDocument;

              QTextCharFormat charFormat;
              charFormat.setFont(QFont("times", 24));

              QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine);
              charFormat.setTextOutline(outlinePen);

              QTextCursor cursor = QTextCursor(document);
              cursor.insertText("Test", charFormat);

              textItem = new QGraphicsTextItem();
              textItem->setDocument(document);
              textItem->setTextInteractionFlags(Qt::TextEditable);

              scene->addItem(textItem);
              @

              1 Reply Last reply
              0
              • D Offline
                D Offline
                danilocesar
                wrote on last edited by
                #7

                Thanks for the code. =)

                I've just asked that because probably someone will have the same problem in the future and a "I solved it" message will not help them =)

                <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
                Software Engineer

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bemax56
                  wrote on last edited by
                  #8

                  Thank you for posting the code. It helps me quite a bit.

                  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 Extensions
                  • Unsolved