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. Disable selection for vertical/horizontal header - QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Disable selection for vertical/horizontal header - QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 2.7k 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.
  • H Offline
    H Offline
    hbatalha
    wrote on 14 Jun 2021, 23:42 last edited by
    #1

    Basically I don't want this:

    Screenshot_3.png
    or this:

    Screenshot_4.png

    I have tried these but they don't work:

    ui->table->verticalHeader()->setSelectionMode(QAbstractItemView::NoSelection);
    ui->table->horizontalHeader()->setSelectionMode(QAbstractItemView::NoSelection);
    
    J 1 Reply Last reply 15 Jun 2021, 06:30
    0
    • H hbatalha
      14 Jun 2021, 23:42

      Basically I don't want this:

      Screenshot_3.png
      or this:

      Screenshot_4.png

      I have tried these but they don't work:

      ui->table->verticalHeader()->setSelectionMode(QAbstractItemView::NoSelection);
      ui->table->horizontalHeader()->setSelectionMode(QAbstractItemView::NoSelection);
      
      J Offline
      J Offline
      JonB
      wrote on 15 Jun 2021, 06:30 last edited by JonB
      #2

      @hbatalha
      Does QHeaderView::setHighlightSections(false) do what you want?
      [EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?]

      H 2 Replies Last reply 16 Jun 2021, 14:21
      0
      • J JonB
        15 Jun 2021, 06:30

        @hbatalha
        Does QHeaderView::setHighlightSections(false) do what you want?
        [EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?]

        H Offline
        H Offline
        hbatalha
        wrote on 16 Jun 2021, 14:21 last edited by
        #3

        @JonB it doesn't do it.

        1 Reply Last reply
        0
        • J JonB
          15 Jun 2021, 06:30

          @hbatalha
          Does QHeaderView::setHighlightSections(false) do what you want?
          [EDIT: Maybe not, since it says "By default, this property is false.", yet it does sound to me like it should be this?]

          H Offline
          H Offline
          hbatalha
          wrote on 16 Jun 2021, 14:27 last edited by
          #4

          @JonB However... QHeaderView::setSectionsClickable(false)

          ui->table->horizontalHeader()->setSectionsClickable(false);
          

          Even thought it is not made for that purpose but it does solve this particular problem of mine.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 16 Jun 2021, 14:29 last edited by
            #5

            Hi
            It does disable it showing it on the headers.
            alt text

            but you want to disable user can click on it to select the row?

            update:
            well yeah setSectionsClickable should do it :)

            H 1 Reply Last reply 16 Jun 2021, 14:31
            0
            • M mrjj
              16 Jun 2021, 14:29

              Hi
              It does disable it showing it on the headers.
              alt text

              but you want to disable user can click on it to select the row?

              update:
              well yeah setSectionsClickable should do it :)

              H Offline
              H Offline
              hbatalha
              wrote on 16 Jun 2021, 14:31 last edited by
              #6

              @mrjj said in Disable selection for vertical/horizontal header - QTableWidget:

              but you want to disable user can click on it to select the row?

              No, I just wanted the headers not to get highlighted when the user hover the mouse.

              M 1 Reply Last reply 16 Jun 2021, 14:33
              0
              • H hbatalha
                16 Jun 2021, 14:31

                @mrjj said in Disable selection for vertical/horizontal header - QTableWidget:

                but you want to disable user can click on it to select the row?

                No, I just wanted the headers not to get highlighted when the user hover the mouse.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 16 Jun 2021, 14:33 last edited by
                #7

                @hbatalha

                ok but even if setSectionsClickable(false); does kill this ability for the user, its ok solution ?

                H 1 Reply Last reply 16 Jun 2021, 14:37
                0
                • M mrjj
                  16 Jun 2021, 14:33

                  @hbatalha

                  ok but even if setSectionsClickable(false); does kill this ability for the user, its ok solution ?

                  H Offline
                  H Offline
                  hbatalha
                  wrote on 16 Jun 2021, 14:37 last edited by
                  #8

                  @mrjj said in Disable selection for vertical/horizontal header - QTableWidget:

                  its ok solution ?

                  Not quite, for example for the vertical header it kills its ability to get selected when its row is selected.

                  M 1 Reply Last reply 16 Jun 2021, 15:10
                  0
                  • H hbatalha
                    16 Jun 2021, 14:37

                    @mrjj said in Disable selection for vertical/horizontal header - QTableWidget:

                    its ok solution ?

                    Not quite, for example for the vertical header it kills its ability to get selected when its row is selected.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 16 Jun 2021, 15:10 last edited by
                    #9

                    @hbatalha
                    Hi
                    I tried to grab the hover event

                    class test : public QHeaderView
                    {
                        Q_OBJECT
                    public:
                        explicit test(Qt::Orientation orientation, QWidget *parent = nullptr ) : QHeaderView(orientation, parent) {}
                    protected:
                        bool event(QEvent *e) override
                        {
                            if ( e->type() == QEvent::HoverEnter ) return true;
                    
                            return QHeaderView::event(e);
                        }
                    
                    };
                    

                    but that broke selection too.
                    so I didn't find a way to get rid of that coloring as it seems mostly to go on inside the d-> private section.

                    H 1 Reply Last reply 16 Jun 2021, 16:27
                    0
                    • M mrjj
                      16 Jun 2021, 15:10

                      @hbatalha
                      Hi
                      I tried to grab the hover event

                      class test : public QHeaderView
                      {
                          Q_OBJECT
                      public:
                          explicit test(Qt::Orientation orientation, QWidget *parent = nullptr ) : QHeaderView(orientation, parent) {}
                      protected:
                          bool event(QEvent *e) override
                          {
                              if ( e->type() == QEvent::HoverEnter ) return true;
                      
                              return QHeaderView::event(e);
                          }
                      
                      };
                      

                      but that broke selection too.
                      so I didn't find a way to get rid of that coloring as it seems mostly to go on inside the d-> private section.

                      H Offline
                      H Offline
                      hbatalha
                      wrote on 16 Jun 2021, 16:27 last edited by
                      #10

                      @mrjj I tried to grab hover through stylesheet but didn't work.

                      I guess selection is a small price to pay to get it done. At least until I find a better way.

                      M 1 Reply Last reply 16 Jun 2021, 16:31
                      0
                      • H hbatalha
                        16 Jun 2021, 16:27

                        @mrjj I tried to grab hover through stylesheet but didn't work.

                        I guess selection is a small price to pay to get it done. At least until I find a better way.

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 16 Jun 2021, 16:31 last edited by
                        #11

                        @hbatalha

                        Yeah, I guess so too. at least until a better way comes as the things i tried would then
                        break selection and no better than setSectionsClickable

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 16 Jun 2021, 16:42 last edited by
                          #12

                          For Qt6 you can override QHeaderView::initStyleOptionForIndex().

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          H 1 Reply Last reply 16 Jun 2021, 18:50
                          2
                          • Christian EhrlicherC Christian Ehrlicher
                            16 Jun 2021, 16:42

                            For Qt6 you can override QHeaderView::initStyleOptionForIndex().

                            H Offline
                            H Offline
                            hbatalha
                            wrote on 16 Jun 2021, 18:50 last edited by
                            #13

                            @Christian-Ehrlicher could you provide a minimal working example?

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on 16 Jun 2021, 19:28 last edited by
                              #14

                              I currently see that setHighlightSections() should also work.

                              could you provide a minimal working example?

                              call the base class impl and then modify QStyleOptionHeader::state the way you want.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              0

                              1/14

                              14 Jun 2021, 23:42

                              • Login

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