Select all cells of a column on single click in qtreeview
-
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 MI 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.
-
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 MI 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.
@AntriX
Did you trysectionPressed()instead ofsectionClicked()?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.
-
@AntriX
Did you trysectionPressed()instead ofsectionClicked()?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.
-
@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. -
@Bonnie said in Select all cells of a column on single click in qtreeview:
setSectionsClickable
Yes This is set to true.
@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)aftersetSortingEnabled(false)as the latter might set it false? -
@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)aftersetSortingEnabled(false)as the latter might set it false?@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? -
@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? -
@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?
-
@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?
-
A AntriX has marked this topic as solved on