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

  • 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->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");



    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.

  • Moderators

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

  • Try the code which shows you the blue color background

  • 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.

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

  • 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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.