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. Customise border radius of QTableView row selection
QtWS25 Last Chance

Customise border radius of QTableView row selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableview
7 Posts 4 Posters 1.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.
  • S Offline
    S Offline
    siya
    wrote on last edited by
    #1

    I would like to customise the QTableView selection border, ie when I select a row in the table, the selection border should be a circular (the border-radius function).

    raven-worxR 1 Reply Last reply
    0
    • S siya

      I would like to customise the QTableView selection border, ie when I select a row in the table, the selection border should be a circular (the border-radius function).

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

      @siya
      subclassing QStyleItemDelegate should do what you want (untested though):

      void MyStyleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,  const QModelIndex &index) const
         {
                 bool isSelected = option.state & QStyle::State_Selected;
                 QStyleOptionViewItem opt = option;
                 opt.state &= ~QStyle::QStyle::State_Selected;
                 QStyledItemDelegate::paint(painter, opt, index);
                 if( isSelected ){
                      // draw rounded rect using painter
                 }
         }
      

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

      JoeCFDJ 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @siya
        subclassing QStyleItemDelegate should do what you want (untested though):

        void MyStyleItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,  const QModelIndex &index) const
           {
                   bool isSelected = option.state & QStyle::State_Selected;
                   QStyleOptionViewItem opt = option;
                   opt.state &= ~QStyle::QStyle::State_Selected;
                   QStyledItemDelegate::paint(painter, opt, index);
                   if( isSelected ){
                        // draw rounded rect using painter
                   }
           }
        
        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        @raven-worx He wants to do this for the whole row, not for one item. I think this may be the last thing for him to do in his project.

        raven-worxR 1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          @raven-worx He wants to do this for the whole row, not for one item. I think this may be the last thing for him to do in his project.

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

          @JoeCFD
          still possible (and the only way i think).
          It needs to be checked if its a middle index or an index on the side of the view and draw the borders accordingly

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

          JoeCFDJ 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @JoeCFD
            still possible (and the only way i think).
            It needs to be checked if its a middle index or an index on the side of the view and draw the borders accordingly

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @raven-worx Agree. That is the part missing in your previous code.

            S 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @raven-worx Agree. That is the part missing in your previous code.

              S Offline
              S Offline
              siya
              wrote on last edited by
              #6

              @JoeCFD @raven-worx Yes that is what I would like. I suppose the onus is on me to read up on the paint function and how to paint borders depending on which index is selected?

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

                Hi,

                You have the model index, so if it's the left most one, draw the left round corners and if it's the right most one, draw the right rounded corner.

                The other option is to use one delegate for the first and last column to do the special painting. Note that this is not the correct solution if your users can reorder the columns.

                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
                1

                • Login

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