I have QTreeWidgetItem set in a QTreeWidget with 2 columns. Both cells got a CheckBox set by setCheckState(...).
When the user unchecks the CheckBox in my first column I uncheck the second CheckBox in column 2.
Now, I would like to prevent the user to check this second CheckBox again. Is it possible to remove this CheckBox in column 2 or to disable only this cell?
So far I have just seen that all the flags work on the complete item and a set CheckBox won't disapear.
Btw. The items are not editable and I don't want to use a QTableWidget/-Item.
Update:
The CheckBox will be automatically inserted by Qt when I call setCheckState for the item:
QTreeWidgetItem *item = new QTreeWidgetItem(ui.TreeWidget);
item->setCheckState(0, Qt::Checked);
After the new the item does not own a CheckBox (by Qt default). Calling setCheckState(...) I automatically insert a CheckBox (here in column 0) with the Qt::CheckState I want.
But after I have done it there's no way to remove the CheckBox - so it seems.
Maybe anyone got a solution how I can get rid of this CheckBox at a later time? Any help is much appreciated!
This will do it:
item->setData(0, Qt::CheckStateRole, QVariant()); //No checkbox at all (what you wanted)
any of these others will show the checkbox space
item->setData(0, Qt::CheckStateRole, Qt::Unchecked); //Unchecked checkbox
item->setData(0, Qt::CheckStateRole, Qt::Checked); //Checked checkbox
item->setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); //Partially checked checkbox (gray)
The setCheckState method can not set 'no check state', only Checked, PartiallyChecked or Unckecked.
Related
The first row is selected by default, when I shift-select the last row I expect that all rows will be selected but no, it only selects the visible rows of the QTableView.
I have a QTableView displaying data from a database-model. It is configured to allow extended selection (ctrl, shift etc) and to select rows only (not cells). The content is changing based on other parameters, and whenever I update the model I select by default the first row of my QTableView.
ui->tableView->setModel(model);
ui->tableView->setColumnHidden(UidColumn, true);
ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->verticalHeader()->hide();
ui->tableView->setAlternatingRowColors(true);
// This is done whenever the content changes
QModelIndex index = model->index(0,0);
ui->tableView->setCurrentIndex(index);
I hide the vertical headers because nothing to display there, and I hide the first column because it is not relevant for the user.
The first row is displayed as selected, I even logged the changes of focus and the tableView->selectionModel()->selectedRows() is always good (i.e. returning QModelIndex(0,0)). But when I do the shift-click on the last row, it is like the first row was never selected at all.
If I manually select the first row (or any row), the next shift-click will work perfectly. If I do a ctrl-click, the multiselection works perfectly. It is like my default selection (done by the code) is ignored with shift-click.
The default QModelIndex(0,0) selects a cell that is part of the hidden column. Even if displayed as a selected row, apparently it messes up the shift-selection.
If I do not hide the first column, it works fine.
If I use QModelIndex index = model->index(0,1); it works fine.
A simpler solution is to do ui->tableView->selectRow(0);
I have QTableWidget with specific row and column. When I click on empty cell a text opens and let user to write on cell. Is there any way to avoid this situation, I mean, to avoid adding text on empty cell?
UPDATE:
I added this part to slot of cellclick(), but empty cells are yet editable,
QTableWidgetItem *item = filesTable->item(row, column);
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
Is there any way to force empty cells to be read-only?
How to show Qtreewidget item as in editable mode? means when a data of that particular column will show it should be look like it can be edit.
Means it should be taken data as input.
QTreeWidgetItem *item=NULL;
item->setBackgroundColor(0,color);
item->setIcon(0,coloricon);
item->setText(0,QString(sample->sampleName.c_str()));
item->setData(0,Qt::UserRole,QVariant::fromValue(samples[i]));
**//I want to show this particular column as in editable mode**
item->setText(1,QString(sample->getSetName().c_str()));
item->setText(2,QString::number(sample->getNormalizationConstant(),'f',2));
I need a piece of code to check that the user has selected at least one row in a QTableWidget
The QTableWidget can be referenced using ui->tableWidget.
I'm trying to check there are selecting, if not, display a message box, if so, moving on to code I have written.
Thanks.
You can obtain the selected rows from the selection model like:
QItemSelectionModel *selectionModel = ui->tableWidget->selectionModel();
QModelIndexList *selectedRows = selectionModel->selectedRows();
if (selectedRows.size() > 0) {
// There is at lease one selected row.
}
I have a dialog list which use Use View dialog for Choices.
I have a row in a table which its appearing depends on the value selected from that dialog list. ( I am using Hide when formula... ) The form has Automatically refresh fields checked.
The problem is that after I select a certain value from the dialog list, and I even had selected Refresh fields on keyword change property, I MUST hit F5 or just TAB ( to go to a next field ) in order to make that row table to appear. I also tried to add uidoc.Refresh at the Exiting/OnChange event(s) of the dialog list.
I have noticed the following:
the refresh works fine for combo box, list box, radio button or check box
the refresh works fine for dialog list where you are using a list of choices / formula.
the refresh doesn't work for dialog list where you are using view dialog for choices ( my case ).
Is there any solution for this issue? I want when I selected a value from the dialog list, immediately the row / line should appear/disappear.
Thank for your time!