How to simplify syntax
-
@VRonin You're a devil in disguise!
Yes, I'm going to try tableViewIt 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? -
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 -
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
@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?@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 click@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?
-
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 :) -
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 -
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@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.@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?@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)? -
@VRonin said in How to simplify syntax:
That walks like a table, quacks like a table and swims like a table
LMAO :D
-
@Pl45m4 It's science: https://en.wikipedia.org/wiki/Duck_test