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. What 's the most pro way to hide focus rect for QTableView?
Forum Updated to NodeBB v4.3 + New Features

What 's the most pro way to hide focus rect for QTableView?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 760 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.
  • jronaldJ Offline
    jronaldJ Offline
    jronald
    wrote on last edited by jronald
    #1

    setStyleSheet is simple, but it seems less efficient, because qss need to be interprected, when finding a more efficient way, I got question

    code below works, but why the second parameter is made to be const?

    void MyStyle::drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
    {
        if (element == CE_ItemViewItem)
        {
            if (option->state & State_HasFocus)
            {
                QStyleOption * option2 = (QStyleOption *)option;
                option2->state ^= State_HasFocus;
                QProxyStyle::drawControl(element, option2, painter, widget);
            }
            else
                QProxyStyle::drawControl(element, option, painter, widget);
        }
        else
        {
            QProxyStyle::drawControl(element, option, painter, widget);
        }    
    }
    

    code below doesn't work, why?

    void MyStyle::drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
    {
        if (element == CE_ItemViewItem)
        {
            if (option->state & State_HasFocus)
            {
                QStyleOption option2(option);
                option2->state ^= State_HasFocus;
                QProxyStyle::drawControl(element, &option2, painter, widget);
            }
            else
                QProxyStyle::drawControl(element, option, painter, widget);
        }
        else
        {
            QProxyStyle::drawControl(element, option, painter, widget);
        }    
    }
    

    And what is the most efficient way to hide the focus rect for QTableView?

    raven-worxR 1 Reply Last reply
    0
    • jronaldJ jronald

      setStyleSheet is simple, but it seems less efficient, because qss need to be interprected, when finding a more efficient way, I got question

      code below works, but why the second parameter is made to be const?

      void MyStyle::drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
      {
          if (element == CE_ItemViewItem)
          {
              if (option->state & State_HasFocus)
              {
                  QStyleOption * option2 = (QStyleOption *)option;
                  option2->state ^= State_HasFocus;
                  QProxyStyle::drawControl(element, option2, painter, widget);
              }
              else
                  QProxyStyle::drawControl(element, option, painter, widget);
          }
          else
          {
              QProxyStyle::drawControl(element, option, painter, widget);
          }    
      }
      

      code below doesn't work, why?

      void MyStyle::drawControl(ControlElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const
      {
          if (element == CE_ItemViewItem)
          {
              if (option->state & State_HasFocus)
              {
                  QStyleOption option2(option);
                  option2->state ^= State_HasFocus;
                  QProxyStyle::drawControl(element, &option2, painter, widget);
              }
              else
                  QProxyStyle::drawControl(element, option, painter, widget);
          }
          else
          {
              QProxyStyle::drawControl(element, option, painter, widget);
          }    
      }
      

      And what is the most efficient way to hide the focus rect for QTableView?

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

      @jronald said in What 's the most pro way to hide focus rect for QTableView?:

      code below works, but why the second parameter is made be const?

      because the purpose of the method is solely drawing, and thus the method doesn't need to change the parameters basically.

      XOR'ing doesn't make any sense: option->state ^= State_HasFocus;
      You are rather looking for something like: option->state &= ~QStyle::State_HasFocus

      Also you can subclass QStyledItemDelegate and do it in there.

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

      jronaldJ 1 Reply Last reply
      7
      • raven-worxR raven-worx

        @jronald said in What 's the most pro way to hide focus rect for QTableView?:

        code below works, but why the second parameter is made be const?

        because the purpose of the method is solely drawing, and thus the method doesn't need to change the parameters basically.

        XOR'ing doesn't make any sense: option->state ^= State_HasFocus;
        You are rather looking for something like: option->state &= ~QStyle::State_HasFocus

        Also you can subclass QStyledItemDelegate and do it in there.

        jronaldJ Offline
        jronaldJ Offline
        jronald
        wrote on last edited by jronald
        #3

        @raven-worx said in What 's the most pro way to hide focus rect for QTableView?:

        because the purpose of the method is solely drawing, and thus the method doesn't need to change the parameters basically.

        To draw according the fixed parameters, ok.

        XOR'ing doesn't make any sense: option->state ^= State_HasFocus;
        You are rather looking for something like: option->state &= ~QStyle::State_HasFocus

        Yes, the latter is simpler. The former also works, because if ensures that State_HasFocus is set, so xor make it zero, more fast, but not human friendly. I prefer the simpler one :)

        Also you can subclass QStyledItemDelegate and do it in there.

        Fine

        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