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] Problem in writing text on QTableWidget using Qpainter.

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.8k 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.
  • M Offline
    M Offline
    M_31
    wrote on last edited by
    #1

    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
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        annahl2m
        wrote on last edited by
        #3

        Try the code which shows you the blue color background

        1 Reply Last reply
        0
        • L Offline
          L Offline
          ludde
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              M_31
              wrote on last edited by
              #6

              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
              0

              • Login

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