Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] Problem in writing text on QTableWidget using Qpainter.

    General and Desktop
    5
    6
    3419
    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.
    • M
      M_31 last edited by

      I want to draw a text on QtableWidget Item after filling the item backGround as blue..

      @
      void DetailedViewImage::paint(QPainter *painter, const QRect &rect,
      const QPalette &palette, EditMode mode) const
      {
      painter->save();
      painter->setRenderHint(QPainter::Antialiasing, true);

      int yOffset = (rect.height() - PaintingScaleFactor) / 2;
      painter->translate(rect.x(), rect.y() + yOffset);
      
      int x1=40,x2=80;
      for (int i = 0; i < myMaxImageCount; ++i)
      {
          if (i < myImageCount)
          {
             // painter->drawPolygon(starPolygon, Qt::WindingFill);
              painter->drawText( QPoint(x1,0.0), "HELLO");
              painter->fillRect(QRect(QPoint(1.0,0.0),QSize(80,20)),Qt::blue);
      
          }
      }
      
      painter->restore();
      

      }

      @

      Here i am able to see the Text "Hello" on TableWidget , but not on the blue color background...both of them are appearing in different position.

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        What if you change the order. First draw the blue rectangle and then add the text?

        Qt Certified Specialist
        www.edalsolutions.be

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

          Try the code which shows you the blue color background

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

            Have you tried using the drawText function that draws the text within a QRect instead? The one you are using uses the y value of the QPoint as the text baseline, which may not be what you expect, or want.

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

              Is there is reason you are not just using a QItemDelegate to do that work?

              1 Reply Last reply Reply Quote 0
              • M
                M_31 last edited by

                yes ...Ludde..i Draw the text within the QRect of my color...its working now...

                Andre..Actaully , i am drawing this text & BgColor using QStyledItemDelegate

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