How to simplify syntax
-
@VRonin You're a devil in disguise!
Yes, I'm going to try tableViewwrote on 18 Sept 2024, 12:16 last edited byIt looks fine, now I need to find a way to get indices for selected columns
any advise? -
It looks fine, now I need to find a way to get indices for selected columns
any advise? -
wrote on 18 Sept 2024, 12:29 last edited by JacobNovitsky
tried to post code chunk, but output msg said it was spm
https://justpaste.it/g6kt5above works, but selects all columns together with one click, I need to be able to do it one by one
please advise -
wrote on 18 Sept 2024, 12:40 last edited by
instead of calling
selectedIndexes
and doing manipulation, have you tried callingselectedColumns
instead? -
wrote on 18 Sept 2024, 12:44 last edited by
void MyWindow::onSelectionChanged() { // Fetch the currently selected columns using selectedColumns() QItemSelectionModel *selectionModel = tableView->selectionModel(); QModelIndexList selectedColumns = selectionModel->selectedColumns(); // Convert QModelIndexList to a list of column indices QList<int> selectedColumnList; for (const QModelIndex &index : selectedColumns) { selectedColumnList.append(index.column()); } // Sort the list of selected column indices std::sort(selectedColumnList.begin(), selectedColumnList.end()); // Print selected column indices qDebug() << "Selected columns:" << selectedColumnList; }
same result
-
void MyWindow::onSelectionChanged() { // Fetch the currently selected columns using selectedColumns() QItemSelectionModel *selectionModel = tableView->selectionModel(); QModelIndexList selectedColumns = selectionModel->selectedColumns(); // Convert QModelIndexList to a list of column indices QList<int> selectedColumnList; for (const QModelIndex &index : selectedColumns) { selectedColumnList.append(index.column()); } // Sort the list of selected column indices std::sort(selectedColumnList.begin(), selectedColumnList.end()); // Print selected column indices qDebug() << "Selected columns:" << selectedColumnList; }
same result
wrote on 18 Sept 2024, 13:10 last edited by@JacobNovitsky said in How to simplify syntax:
same result
so what does
qDebug()
atually print there? -
@JacobNovitsky said in How to simplify syntax:
same result
so what does
qDebug()
atually print there?wrote on 18 Sept 2024, 13:13 last edited by@VRonin it prints Selected columns: QList(0)
but I can select only all lines with one click -
@VRonin it prints Selected columns: QList(0)
but I can select only all lines with one clickwrote on 18 Sept 2024, 13:14 last edited by@JacobNovitsky said in How to simplify syntax:
but I can select only all lines with one click
I'm confused, what is the behaviour you would want to happen?
-
wrote on 18 Sept 2024, 13:17 last edited by
Lets say, I selected line 1 3 and 9
or I selected lines 1 2 3
I need to 1) select only 123 out of 9 lines total
2) I need to get selected indices :) -
wrote on 18 Sept 2024, 14:25 last edited by VRonin
In your code you have
tableView->setSelectionBehavior(QAbstractItemView::SelectColumns);
that makes it so when you select a cell, the entire column gets selected. I don't believe that's what you want, delete that line -
wrote on 18 Sept 2024, 16:27 last edited by
https://justpaste.it/dwq1c
Above is my last working code, it selects rows line by line as requested,
but outputs
Selected columns: QList()
with no inidicesI believe problem in
QList<int> MyWindow::getSelectedColumns()
Need to clarify/fix this syntax -
wrote on 18 Sept 2024, 16:34 last edited by
Yes, you need to revert to
selectedIndexes
instead ofselectedColumns
. My suggestion above was a misunderstanding of your requirement -
https://justpaste.it/dwq1c
Above is my last working code, it selects rows line by line as requested,
but outputs
Selected columns: QList()
with no inidicesI believe problem in
QList<int> MyWindow::getSelectedColumns()
Need to clarify/fix this syntaxwrote on 18 Sept 2024, 16:36 last edited by@JacobNovitsky
I'm not sure I follow. If the user selects "lines" (rows) then you won't get any selected columns back? (Because whole columns are not selected, just certain columns within certain rows.) To see which columns are selected within various selected rows use QModelIndexList QItemSelectionModel::selectedIndexes() const, which gives all selected cells and then look at thecolumn()
values within that. If that is what you are looking for. -
@JacobNovitsky
I'm not sure I follow. If the user selects "lines" (rows) then you won't get any selected columns back? (Because whole columns are not selected, just certain columns within certain rows.) To see which columns are selected within various selected rows use QModelIndexList QItemSelectionModel::selectedIndexes() const, which gives all selected cells and then look at thecolumn()
values within that. If that is what you are looking for.wrote on 18 Sept 2024, 16:38 last edited by@JonB oh, it does indeed outputs columns selected, but I really meant rows :)
So I do look for the same but for rows? -
@JonB oh, it does indeed outputs columns selected, but I really meant rows :)
So I do look for the same but for rows?wrote on 18 Sept 2024, 16:42 last edited by@JacobNovitsky
Well, yes!
There are 3 methods to see what is selected:selectedColumns()
--- just complete columns selected.selectedRows()
--- just complete rows selectedselectedIndexes()
--- any mix of individual cells (not necessarily contiguous) selected. Always valid. Inspect each item'srow()
andcolumn()
to see what they are, could have any values.
-
-
That walks like a table, quacks like a table and swims like a table. Are you sure you don't actually want to just use
QTableWidget
(orQTableView
+ model if you want to be fancy)?wrote on 19 Sept 2024, 12:38 last edited by@VRonin said in How to simplify syntax:
That walks like a table, quacks like a table and swims like a table
LMAO :D
-
@VRonin said in How to simplify syntax:
That walks like a table, quacks like a table and swims like a table
LMAO :D
wrote on 19 Sept 2024, 12:52 last edited by@Pl45m4 It's science: https://en.wikipedia.org/wiki/Duck_test
-
@Pl45m4 It's science: https://en.wikipedia.org/wiki/Duck_test
18/26