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. How to remove this effect?
Forum Updated to NodeBB v4.3 + New Features

How to remove this effect?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 598 Views 2 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.
  • D Offline
    D Offline
    deleted385
    wrote on last edited by
    #1

    When I hover over the items, the top line becomes thinner or is restored to original style like this:

    x1.gif

    The code is almost same as this, I've added a UserRole for those Total. In the Delegate, I've these:

    Delegate::Delegate(){ }
    void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{   
        painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
        QStyledItemDelegate::paint(painter, option, index);
        if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){
            painter->drawLine(option.rect.topLeft(), option.rect.topRight());
            painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        }
    }
    
    raven-worxR 1 Reply Last reply
    0
    • D deleted385

      When I hover over the items, the top line becomes thinner or is restored to original style like this:

      x1.gif

      The code is almost same as this, I've added a UserRole for those Total. In the Delegate, I've these:

      Delegate::Delegate(){ }
      void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{   
          painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
          QStyledItemDelegate::paint(painter, option, index);
          if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){
              painter->drawLine(option.rect.topLeft(), option.rect.topRight());
              painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
          }
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Emon-Haque
      your line overlaps indexes and i guess you used a (default) pen with a width of 2px.
      So the half of the line is overdrawn when the index/row is repainted without the highlighting.

      you need to translate the line by the half of the line/pen width to ensure that it is inside the index boundaries.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      D 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @Emon-Haque
        your line overlaps indexes and i guess you used a (default) pen with a width of 2px.
        So the half of the line is overdrawn when the index/row is repainted without the highlighting.

        you need to translate the line by the half of the line/pen width to ensure that it is inside the index boundaries.

        D Offline
        D Offline
        deleted385
        wrote on last edited by deleted385
        #3

        @raven-worx, this translation works:

        void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{   
            painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
            QStyledItemDelegate::paint(painter, option, index);
            if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){
                painter->save();
                painter->translate(0,1);
                painter->drawLine(option.rect.topLeft(), option.rect.topRight());
                painter->restore();
                painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
            }
        }
        

        x2.gif

        Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?

        raven-worxR 1 Reply Last reply
        0
        • D deleted385

          @raven-worx, this translation works:

          void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{   
              painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
              QStyledItemDelegate::paint(painter, option, index);
              if(index.siblingAtColumn(0).data(Qt::UserRole) == "Aggregate" && index.column() > 0){
                  painter->save();
                  painter->translate(0,1);
                  painter->drawLine(option.rect.topLeft(), option.rect.topRight());
                  painter->restore();
                  painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
              }
          }
          

          x2.gif

          Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Emon-Haque
          just a tip:

          • QPainter save/restore is rather costly and should be avoided if you are after performance. Better just translate the line coordiantes
          • the generic way would be to calculate the translation based on the pen width: int translate = qCeil(painter->pen().width() * 0.5)

          Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?

          i dont understand your question

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          D 1 Reply Last reply
          3
          • raven-worxR raven-worx

            @Emon-Haque
            just a tip:

            • QPainter save/restore is rather costly and should be avoided if you are after performance. Better just translate the line coordiantes
            • the generic way would be to calculate the translation based on the pen width: int translate = qCeil(painter->pen().width() * 0.5)

            Is there an extra 1 px/pt gap at the end of last child of each node or at the end of each Total?

            i dont understand your question

            D Offline
            D Offline
            deleted385
            wrote on last edited by deleted385
            #5

            @raven-worx, the top line is now 1 px/pt below the original position so there's an extra 1px/pt gap between those top lines and last Some Text -1,000 1000 of each node, right? And all those Total 1,000 1000 is 1 px/pt closer to the top line.

            raven-worxR 1 Reply Last reply
            0
            • D deleted385

              @raven-worx, the top line is now 1 px/pt below the original position so there's an extra 1px/pt gap between those top lines and last Some Text -1,000 1000 of each node, right? And all those Total 1,000 1000 is 1 px/pt closer to the top line.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Emon-Haque
              i dont see an additional gap.
              you may want to read this: https://doc.qt.io/qt-5/coordsys.html

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1

              • Login

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