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. QHeaderView::paintSection

QHeaderView::paintSection

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

    [code]
    void HeaderView::paintSection(QPainter *painter, const QRect &, int) const
    {
    painter->drawText(0, 0, "abcde");
    }
    [/code]

    I need to draw text in derived from QHeaderView class. But this code does not work.

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

      Hi,

      What do you mean by "it does not work" ? What does not work ? What are you expecting to get ? What are you currently getting ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        za83
        wrote on last edited by
        #3

        [quote author="SGaist" date="1408998200"]Hi,

        What do you mean by "it does not work" ? What does not work ? What are you expecting to get ? What are you currently getting ?[/quote]

        The text does not drawing.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Are you sure it's called ? And why don't you draw in the given rectangle ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            za83
            wrote on last edited by
            #5

            Yes, I am sure. If I call drawRect(0, 0, 10, 10) the rectangle is drawing. But the text is not painting.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What happens if you call

              @void HeaderView::paintSection(QPainter *painter, const QRect &rect, int) const
              {
              painter->drawText(rect, Qt::AlignCenter, "abcde");
              }@

              ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                za83
                wrote on last edited by
                #7

                Nothing happens. But I solved the problem using
                [code]
                painter->save();
                QHeaderView::paintSection(painter, rect, logicalIndex);
                painter->restore();
                [/code]
                I don't know what does it mean but it works.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  It calls the base implementation of painSection. So basically, you can remove the function from your class

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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