Eclipse scout Neon disabled only one row in table - row

I would like to disable only one row in Table.
So after performing some action I would like to disabled one row. (I have table that is editable and "disabled" row for me mean that I can't change value)
row.setEnabled(false);
does not work, because it disable whole table.
Edit :
I actually need enabling/ disabling cells in rows.

I figure it out.
Interfaces of row and cell doesn't have this specification, but if you use method
#Override
protected void execDecorateCell(final Cell view, final ITableRow row, final IColumn<?> col) {
super.execDecorateCell(view, row, col);
// set cell editable.
view.setEditable(false);
}
And this disable specific row from editing.
If you would like to disable specific row, you could limit it by row and col.
So you can disable really specific cell. Don't forget to add
else {
view.setEditable(true);
}
so when this method is called again it will update old cells (if they maybe are enabled this time).

Related

QTreeView/QHeaderView resize only first column to stretch and interactive both

I have a QTreeView which has 5 columns. The requirement is to stretch only the first column but all the 5 columns should be resizable by user(i.e. they can be interactive as well) also. So I wrote the following code:
int numCols = myModel->columnCount();
for(int i=0;i<numCols;i++)
{
myQTreeView->resizeColumnToContents(i);
if(i==0)
{
myQTreeView->header()->setResizeMode(i,QHeaderView::Stretch);
}
else
{
myQTreeView->header()->setResizeMode(i,QHeaderView::Interactive);
}
}
But this does not work as expected for 1st column. Although the 1st column stretches but it is not resizable/interactive like rest of the columns. Hence I want to add stretch+interactive for the 1st column. Rest of the 4 columns might as well be interactive only.
Is this possible?
According to the documentation for QHeaderView::ResizeMode, when the mode has been set to QHeaderView::Stretch...
The size cannot be changed by the user or programmatically.
So, no, I don't think it's possible to achieve what you want using the standard APIs.
You could try setting the resize mode to QHeaderView::Custom and overriding the various mouse event handlers in the QHeaderView by either installing an event filter on the existing QHeaderView or by creating your own class inheriting from QHeaderView and installing an instance of it in your view via QTreeView::setHeader.

Boolean column(Check box) cell in Infragistics UltraGrid should be disabled based on a condition in InitializeRow event

In Infragistics Ultra Grid I have to disable a Boolean (Check box) cell based on a condition in Initialize Row event
PS: I don't want entire column to be disabled. Just only cell should be disabled (cell which contains check box should also be disabled).
I kept code like below
e.Row.Activation = Activation.NoEdit
This code is disabling all the cells in ultra grid row. But a Boolean checkbox which is present in a cell is not getting disabled.
try something like:
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{ // deactivate boolean in cell 0
//ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation =
// Infragistics.Win.UltraWinGrid.Activation.Disabled;
e.Row.Cells[0].Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled;
}
Other choices available beside Disabled are: ActivateOnly, AllowEdit, and NoEdit
You can always come back and activate it.
Here is another idea. Instead of a boolean cell, make it a System.Drawing.Bitmap and create your check boxes, checked, and unchecked.
and then create/modify an image(s) for disabled.
On the cell click event, change the cell image according to your needs. If need be, create an additional hidden column to store the state/value of the cell. This is something I did when I created/translated a Java version of my c# application to run on other platforms and it worked out great. (Feel free to use these images if it helps)
Found the root cause. In base class there is one mouse down event due to which checkbox in ultragrid is being enabled. Even though if i kept logic like this e.Row.Activation = Activation.NoEdit.
Thank you all for your help.

QTableWidget - combobox delegate how do I allow different options per cell

Aloha
I have a QTableWidget with two columns that are currently using a ComboboxDelegate (my subclass of QItemDelegate) to present options to the user. I'd like the choice in the first column to effect the options available in the second, for the current row only.
E.g have a list of cars in the first column, and in the second a list of colours which are available for that car. Other rows to have different cars selected and thus different colour choices available.
From what I can see, I can only set an item delegate per row or column, so I can't see how to change the options in the second column's delegate without affecting all the other rows.
Is this possible? I'd really like to avoid going to a full view/model separation as I have quite a bit of code looking at this QTableWidget already (and I'm under time pressure)
Well for those interested; I went back to my pre-delegate approach, which was to use QTableWidget::setItemWidget() to provide a combobox widget for each cell.
I subclassed qcombobox to take a reference to the table, and connected the combobox CurrentIndexChanged with a slot to update the table data.
(setting a widget in a cell does not affect the tablewidget data unless you do this).
Using a full combobox like this is more expensive than an itemdelegate, but my tables are very small so I can get away with it. The rendering of the combobox is not as nice as the delegate (the combobox is visible all the time instead of only during editing in the delegate's case), but with time I'm sure I can improve on this.

Qt Delete selected row in QTableView

I want to delete a selected row from the table when I click on the delete button.
But I can't find anything regarding deleting rows in the Qt documentation. Any ideas?
You can use the bool QAbstractItemModel::removeRow(int row, const QModelIndex & parent = QModelIndex()) functionality for this.
Here you can find an example for all this.
Also, here is an inline quote from that documentation:
removeRows()
Used to remove rows and the items of data they contain
from all types of model. Implementations must call beginRemoveRows()
before inserting new columns into any underlying data structures, and
call endRemoveRows() immediately afterwards.
The second part of the task would be to connect the button's clicked signal to the slot executing the removal for you.
If you are removing multiple rows you can run into some complications using the removeRow() call. This operates on the row index, so you need to remove rows from the bottom up to keep the row indices from shifting as you remove them. This is how I did it in PyQt, don't know C++ but I imagine it is quite similar:
rows = set()
for index in self.table.selectedIndexes():
rows.add(index.row())
for row in sorted(rows, reverse=True):
self.table.removeRow(row)
Works perfectly for me! However one thing to know, in my case this function gets called when a user clicks on a specific cell (which has a pushbutton with an 'X'). Unfortunately when they click on that pushbutton it deselects the row, which then prevents it from getting removed. To fix this I just captured the row of the sender and appended it to the "remove_list" at the very beginning, before the "for loops". That looks like this:
rows.add(self.table.indexAt(self.sender().pos()).row())
You can use another way by deleting the row from database, then clear the model and fill it again, this solution is also safe when you are removing multiple rows.

Qt - QTableView - Clickable button in table row

I require a button/link within a table row of a QTableView. This is to open a dialog to allow that row to be edited more efficiently.
After hours of looking on the web I am yet to find a decent example.
I am aware that this is likely to be done using a QItemDelegate, but I am unsure how to have a functional widget within the row without forcing the item into edit mode first.
Any help would be greatly appreciated.
You can use setIndexWidget for that, see the Qt documentation for more information.
As an example, to embed a push button in the first column of the second row (untested code):
tableView->setIndexWidget(tableView->model()->index(2, 1), new QPushButton);
You could emulate the functionality of a link by underlining the clickable text, then capturing the cell click via the cellClicked(row, col) signal and check that col == editColumn. Then row would correspond to which item you are editing.
For example,
Data Name | Value 1 | Value 2 | Edit
connect (tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(editSlot(int, int)));
...
void ClassName::editSlot(int row, int col){
if (col == 3) {
doWork(row);
}
}