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. Paint QTableView with rounded corners.
QtWS25 Last Chance

Paint QTableView with rounded corners.

Scheduled Pinned Locked Moved Solved General and Desktop
qtableviewqtableview c++qpainter
4 Posts 2 Posters 2.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.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by tokafr
    #1

    Hello.
    I want to have a QTableView widget which will have a rounded corners. for that I create a class MyTableView which inherits QTableView and reimplement the paintEvent method. I do:

    void MyTableView::paintEvent(QPaintEvent *event)
    {
    QTableView::paintEvent(event);

    QPainter painter(this);

    int radius = 6;

    painter.setRenderHint(QPainter::Antialiasing);

    QPen pen = painter.pen();

    painter.setPen(Qt::NoPen);

    painter.drawRoundedRect(rect().adjusted(1, 1, -1, -1), radius, radius,
    Qt::AbsoluteSize);
    painter.drawRoundedRect(rect().adjusted(1, 1, -1, -rect().height() + 10), 2, 2,
    Qt::AbsoluteSize);

    
    and I have:
    [03.11.16 10:10:31.540] QPainter::begin: Widget painting can only begin as a result of a paintEvent
    [03.11.16 10:10:31.540] QPainter::setRenderHint: Painter must be active to set rendering hints
    [03.11.16 10:10:31.540] QPainter::pen: Painter not active
    [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
    [03.11.16 10:10:31.540] QPainter::setBrush: Painter not active
    [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
    [03.11.16 10:10:31.544] QPainter::begin: Widget painting can only begin as a result of a paintEvent
    [03.11.16 10:10:31.545] QPainter::setRenderHint: Painter must be active to set rendering hints
    [03.11.16 10:10:31.545] QPainter::pen: Painter not active
    
    what am I doing wrong? thank you.
    D T 2 Replies Last reply
    0
    • T tokafr

      Hello.
      I want to have a QTableView widget which will have a rounded corners. for that I create a class MyTableView which inherits QTableView and reimplement the paintEvent method. I do:

      void MyTableView::paintEvent(QPaintEvent *event)
      {
      QTableView::paintEvent(event);

      QPainter painter(this);

      int radius = 6;

      painter.setRenderHint(QPainter::Antialiasing);

      QPen pen = painter.pen();

      painter.setPen(Qt::NoPen);

      painter.drawRoundedRect(rect().adjusted(1, 1, -1, -1), radius, radius,
      Qt::AbsoluteSize);
      painter.drawRoundedRect(rect().adjusted(1, 1, -1, -rect().height() + 10), 2, 2,
      Qt::AbsoluteSize);

      
      and I have:
      [03.11.16 10:10:31.540] QPainter::begin: Widget painting can only begin as a result of a paintEvent
      [03.11.16 10:10:31.540] QPainter::setRenderHint: Painter must be active to set rendering hints
      [03.11.16 10:10:31.540] QPainter::pen: Painter not active
      [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
      [03.11.16 10:10:31.540] QPainter::setBrush: Painter not active
      [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
      [03.11.16 10:10:31.544] QPainter::begin: Widget painting can only begin as a result of a paintEvent
      [03.11.16 10:10:31.545] QPainter::setRenderHint: Painter must be active to set rendering hints
      [03.11.16 10:10:31.545] QPainter::pen: Painter not active
      
      what am I doing wrong? thank you.
      D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #2

      @tokafr

      You can use: QPainter painter(this->viewport());

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tokafr
        wrote on last edited by
        #3

        Ok I found the answer. I added
        setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
        flag to the widget I am repainting

        1 Reply Last reply
        0
        • T tokafr

          Hello.
          I want to have a QTableView widget which will have a rounded corners. for that I create a class MyTableView which inherits QTableView and reimplement the paintEvent method. I do:

          void MyTableView::paintEvent(QPaintEvent *event)
          {
          QTableView::paintEvent(event);

          QPainter painter(this);

          int radius = 6;

          painter.setRenderHint(QPainter::Antialiasing);

          QPen pen = painter.pen();

          painter.setPen(Qt::NoPen);

          painter.drawRoundedRect(rect().adjusted(1, 1, -1, -1), radius, radius,
          Qt::AbsoluteSize);
          painter.drawRoundedRect(rect().adjusted(1, 1, -1, -rect().height() + 10), 2, 2,
          Qt::AbsoluteSize);

          
          and I have:
          [03.11.16 10:10:31.540] QPainter::begin: Widget painting can only begin as a result of a paintEvent
          [03.11.16 10:10:31.540] QPainter::setRenderHint: Painter must be active to set rendering hints
          [03.11.16 10:10:31.540] QPainter::pen: Painter not active
          [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
          [03.11.16 10:10:31.540] QPainter::setBrush: Painter not active
          [03.11.16 10:10:31.540] QPainter::setPen: Painter not active
          [03.11.16 10:10:31.544] QPainter::begin: Widget painting can only begin as a result of a paintEvent
          [03.11.16 10:10:31.545] QPainter::setRenderHint: Painter must be active to set rendering hints
          [03.11.16 10:10:31.545] QPainter::pen: Painter not active
          
          what am I doing wrong? thank you.
          T Offline
          T Offline
          tokafr
          wrote on last edited by
          #4
          This post is deleted!
          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