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 - paint and html
QtWS25 Last Chance

QGraphicsTextItem - paint and html

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • Z Offline
    Z Offline
    ziggx
    wrote on last edited by
    #1

    Hi there,

    I have subclassed QGraphicsTextItem and I want to put a semi transparent box behind the HTML formatted text. But doing the following, in the paint routine, doesn't work:

         painter->fillRect(boundingRect(),brush);
        QGraphicsTextItem::paint(painter,option,widget);
    
    

    If I use plainText, there is no problem drawing a rectangle behind the text. But when I use setHTML, the box is not drawn. Am I missing something or is this something that can't be done in a subclassed QGraphicsTextItem? Any pointers would be appreciated.

    Best wishes (and seasons greetings)
    Ziggx

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Can it be something in the HTML ?
      If i use the Diagram example and use setHTML its still transparent.

      alt text

      auto html =
      R"(
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
      <html>
       <head>
          <meta name="qrichtext" content="1" />
          <style type="text/css">
             p, li { white-space: pre-wrap; }
          </style>
       </head>
       <body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
          <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">This</span> is <span style=" font-size:14pt; font-weight:600;">HTML</span><span style=" font-style:italic;">text</span></p>
       </body>
      </html>
       )";
      
          DiagramTextItem* item = qgraphicsitem_cast<DiagramTextItem*>(selectedItems().first());
          item->setHtml(html) ;
      
      Z 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Can it be something in the HTML ?
        If i use the Diagram example and use setHTML its still transparent.

        alt text

        auto html =
        R"(
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
        <html>
         <head>
            <meta name="qrichtext" content="1" />
            <style type="text/css">
               p, li { white-space: pre-wrap; }
            </style>
         </head>
         <body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
            <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">This</span> is <span style=" font-size:14pt; font-weight:600;">HTML</span><span style=" font-style:italic;">text</span></p>
         </body>
        </html>
         )";
        
            DiagramTextItem* item = qgraphicsitem_cast<DiagramTextItem*>(selectedItems().first());
            item->setHtml(html) ;
        
        Z Offline
        Z Offline
        ziggx
        wrote on last edited by
        #3

        @mrj interesting. I will check that example. Thanks for the pointer...

        Best wishes
        Ziggx

        Z 1 Reply Last reply
        0
        • Z ziggx

          @mrj interesting. I will check that example. Thanks for the pointer...

          Best wishes
          Ziggx

          Z Offline
          Z Offline
          ziggx
          wrote on last edited by
          #4

          Thank you mrjj. That will help me do what I want. I had never looked at the Diagram example - just goes to show, the information is often right under your nose.

          Thanks again and have a very merry and happy Christmas

          Best wishes
          Ziggx

          mrjjM 1 Reply Last reply
          0
          • Z ziggx

            Thank you mrjj. That will help me do what I want. I had never looked at the Diagram example - just goes to show, the information is often right under your nose.

            Thanks again and have a very merry and happy Christmas

            Best wishes
            Ziggx

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ziggx
            Super.
            I often suggest that sample if people want to make any kind of diagram editor as its a good start.
            Yeah, every now and then our local Qt Lord suggests some class i never saw before :)

            Merry Christmas and a glorious new year

            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