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. Select all cells of a column on single click in qtreeview
Forum Updated to NodeBB v4.3 + New Features

Select all cells of a column on single click in qtreeview

Scheduled Pinned Locked Moved Solved General and Desktop
@qheaderview @@qtreeview@ qsortfilter
10 Posts 3 Posters 1.4k 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.
  • A Offline
    A Offline
    AntriX
    wrote on last edited by
    #1

    Hi,

    I Have a tree view which contains data in table format like:

    Col1       Col2     Col3     Col4 
    >  H1
    >                 B            C           D
    >                 E            F           G
    >  H2
    >                 H           I             J
    >                 K           L            M
    

    I want to select all cells of a column when column header is clicked.
    I tried implementing sectionClicked signal in my treeview but this is not getting hit if sorting is disabled.
    I am performing sorting on doubleclick of column header by using sectionDoubleClicked signal. I am using QSortFilterProxyModel for sorting.

    Can any please help me how can i select all cells of a column in QTreeView on single click.

    JonBJ 1 Reply Last reply
    0
    • A AntriX

      Hi,

      I Have a tree view which contains data in table format like:

      Col1       Col2     Col3     Col4 
      >  H1
      >                 B            C           D
      >                 E            F           G
      >  H2
      >                 H           I             J
      >                 K           L            M
      

      I want to select all cells of a column when column header is clicked.
      I tried implementing sectionClicked signal in my treeview but this is not getting hit if sorting is disabled.
      I am performing sorting on doubleclick of column header by using sectionDoubleClicked signal. I am using QSortFilterProxyModel for sorting.

      Can any please help me how can i select all cells of a column in QTreeView on single click.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @AntriX
      Did you try sectionPressed() instead of sectionClicked()?

      Otherwise, I admit I don't know, but at a guess either something like this based on mouse down or it must be possible to separate off the sorting behaviour from the section click notification.

      A 1 Reply Last reply
      0
      • JonBJ JonB

        @AntriX
        Did you try sectionPressed() instead of sectionClicked()?

        Otherwise, I admit I don't know, but at a guess either something like this based on mouse down or it must be possible to separate off the sorting behaviour from the section click notification.

        A Offline
        A Offline
        AntriX
        wrote on last edited by
        #3

        @JonB Yes I have tried using sectionPressed() too but no success.
        do you have any idea how can I disable sorting on section click when setSortingEnabled is set to true.

        B 1 Reply Last reply
        0
        • A AntriX

          @JonB Yes I have tried using sectionPressed() too but no success.
          do you have any idea how can I disable sorting on section click when setSortingEnabled is set to true.

          B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

          @AntriX Did you try QHeaderView::setSectionsClickable() ?

          A 1 Reply Last reply
          0
          • B Bonnie

            @AntriX Did you try QHeaderView::setSectionsClickable() ?

            A Offline
            A Offline
            AntriX
            wrote on last edited by
            #5

            @Bonnie said in Select all cells of a column on single click in qtreeview:

            setSectionsClickable

            Yes This is set to true.

            JonBJ 1 Reply Last reply
            0
            • A AntriX

              @Bonnie said in Select all cells of a column on single click in qtreeview:

              setSectionsClickable

              Yes This is set to true.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @AntriX
              I was about to ask that. Then the following works for me:

                  tv->setSortingEnabled(false);
                  tv->header()->setSectionsClickable(true);
                  QObject::connect(tv->header(), &QHeaderView::sectionClicked, tv, [](int logicalIndex) { qDebug() << logicalIndex; });
              

              Maybe make sure you call setSectionsClickable(true) after setSortingEnabled(false) as the latter might set it false?

              A 1 Reply Last reply
              2
              • JonBJ JonB

                @AntriX
                I was about to ask that. Then the following works for me:

                    tv->setSortingEnabled(false);
                    tv->header()->setSectionsClickable(true);
                    QObject::connect(tv->header(), &QHeaderView::sectionClicked, tv, [](int logicalIndex) { qDebug() << logicalIndex; });
                

                Maybe make sure you call setSectionsClickable(true) after setSortingEnabled(false) as the latter might set it false?

                A Offline
                A Offline
                AntriX
                wrote on last edited by
                #7

                @JonB Thank you for your suggestion. I am able to get sectionClicked signal now by changing some code in my wrapper headerview class. Wrapper header view class was eating sectionClicked signal.
                Now I Have the section number that I clicked. Do you have any idea how can I select all the cells in that column?

                JonBJ 1 Reply Last reply
                0
                • A AntriX

                  @JonB Thank you for your suggestion. I am able to get sectionClicked signal now by changing some code in my wrapper headerview class. Wrapper header view class was eating sectionClicked signal.
                  Now I Have the section number that I clicked. Do you have any idea how can I select all the cells in that column?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @AntriX
                  I think void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) with QItemSelectionModel::Columns?

                  A 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @AntriX
                    I think void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) with QItemSelectionModel::Columns?

                    A Offline
                    A Offline
                    AntriX
                    wrote on last edited by
                    #9

                    @JonB Thank you. It worked. Do you know any signal which comes up when header is clicked along with ctrl key pressed. I can not find any direct signal for this. I am thinking of implementing it by setting flag when ctrl key pressed. Any better approach to achieve this?

                    JonBJ 1 Reply Last reply
                    0
                    • A AntriX

                      @JonB Thank you. It worked. Do you know any signal which comes up when header is clicked along with ctrl key pressed. I can not find any direct signal for this. I am thinking of implementing it by setting flag when ctrl key pressed. Any better approach to achieve this?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @AntriX
                      There isn't a separate signal depending on state of modifier buttons like Ctl. You have to attach to mouse down or up and check for modifiers there, or check for global state in normal click slot, I can't recall which is best.

                      1 Reply Last reply
                      0
                      • A AntriX has marked this topic as solved on

                      • Login

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