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.8k 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.
  • JonBJ JonB

    @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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      0
      • mrjjM mrjj

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

        mrjjM 1 Reply Last reply
        0
        • H hbatalha

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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
          0
          • mrjjM mrjj

            @hbatalha

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

            H Offline
            H Offline
            hbatalha
            wrote on 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.

            mrjjM 1 Reply Last reply
            0
            • H hbatalha

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              0
              • mrjjM mrjj

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

                mrjjM 1 Reply Last reply
                0
                • H hbatalha

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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 Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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
                    2
                    • Christian EhrlicherC Christian Ehrlicher

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

                      H Offline
                      H Offline
                      hbatalha
                      wrote on last edited by
                      #13

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

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 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

                        • Login

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