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. QGraphicsTextItem multiple fonts
Forum Updated to NodeBB v4.3 + New Features

QGraphicsTextItem multiple fonts

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.0k 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.
  • M Offline
    M Offline
    mikefire345
    wrote on last edited by
    #1

    I am makings a graphics editor. It seems QT does almost exactly what I want. But it seems QGraphicsTextItem can only handle one font. Is there a way to get QGraphicsTextItem to handle multiple fonts? Or alternatively, is there an easy way to get QTextEdit to interact with a QGraphicsScene?

    Thanks in advanced

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      "QGraphicsTextItem::setFont":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#setFont

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

        Thanks or your quick reply. I understand that I can set the font for the entire string inside the QGraphicsTextItem. I want to have MULTIPLE fonts within a SINGLE QGraphicsTextItem though. Is there any simple way to do this? using setFont() will change the font for the entire item, not any new text entered, for example.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          I think the easiest way is "QGraphicsTextItem::setHtml":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#setHtml
          For example
          @
          <font face="times, times new roman, serif" size=4>This is times or times new roman</font>
          @
          will write "This is times or times new roman" with point size = 4

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mikefire345
            wrote on last edited by
            #5

            Is there an easy way to this though? When a user clicks the BOLD button, i want to be able to insert the selected or new text as bold. This seems to be a nontrivial task if I am going to be dealing with many user inputs and html. QTextEdit seems to support what I need, is there a way to make this place nicely with graphicsCanvas?

            Thanks

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #6

              Other solution is to "QGraphicsTextItem::setDocument":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#setDocument

              Also can override "QGraphicsTextItem::paint":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#paint and draw text as you want.

              Also you can use "QGraphicsProxyWidget":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsproxywidget.html and "setWidget":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsproxywidget.html#setWidget your QTextEdit

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mikefire345
                wrote on last edited by
                #7

                thanks, I'll look into these three possibilities

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cincirin
                  wrote on last edited by
                  #8

                  Note that

                  bq. The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.
                  QTextDocument is a container for structured rich text documents, providing support for styled text and various types of document elements, such as lists, tables, frames, and images. They can be created for use in a QTextEdit, or used independently.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jupiter
                    wrote on last edited by
                    #9

                    you can also use qtextcharformat and merge it

                    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