QTableView toggle setEditTriggers - toggle

I have a checkbox to toggle the EDIT state of a QTableView.
void QPcbView::editToggle(bool editable)
{
if(editable)
this->setEditTriggers(QTableView::AllEditTriggers);
else
this->setEditTriggers(QTableView::NoEditTriggers);
}
This DOES work, but the view is not updated. Meaning when I toggle from editable to non-editable, the cell, that is currently selected stays editable, until it loses focus. How can I fix this behavior? I want my tableview to reflect the EDIT state instantly.

Calling this->update() may work. Or you can check the checkbox value in the model data method.

Related

ag-grid React refreshCells is not affected by state changes

my react grid has a some row values that depends on state (Actually has a slider column).
But i need to show new slider value after state changed by slider. I did it by call redrawRows() because refreshCells() is not changing cell value as state. refreshcells is does nothing into slider.
redrawRows working good but losing mousedown event on slider. i changing slider value with mouse and slider's mousedown handling is lost after redrawRows. I must re press mouse button on every slider value change
Why refreshCells does not update cell value?
For the refreshCells to work, your slider cell renderer component should implement refresh() method.
As per the docs -
To handle refresh, implement logic inside the refresh() method inside
your component and return true. If you do not want to handle refresh,
just return false from the refresh method (which will tell the grid
you do not handle refresh and your component will be destroyed and
recreated if the underlying data changes).
Refresh Cells: api.refreshCells(cellRefreshParams) - Gets the grid to
refresh all cells. Change detection will be used to refresh only cells
who's display cell values are out of sync with the actual value. If
using a cellRenderer with a refresh method, the refresh method will
get called.
In your case, it may be possible that the refresh method is not being called.
Please read more on cell renderer component life cycle here

Call UITextField Editing Did Begin only once

When the user click on the textField i send them to another screen (using Editing did begin) so he can select the option he wants (i use the textfield for design purpose so i cant change this for a button or pickerView or etc)
The question is, when he selects the option he wants i pop this view and send the value back to the textField screen (using delegate).
Now i tried to do textField.resignFirstResponder() but this does not work, since the textField is still selected the action goes into a loop. I can use textField.isDisable but the user can't change the value anymore.
I can fix this by simple putting
if(textField.text != "")
{
return
}
In the textField action. But this is far away from a solution, its more like band-aid on a leak.
And with this if the user select the textField again since i have the if above in the code he will not go to the select screen unless he delete the entire text.
How can i solve this? Since resignFirstResponder its not working. Maybe im doing it wrong?
Please set Delegate for your textfield
textFieldName.delegate = self

image is reverting to original when scrolling uitableview

I have a button inside each cell. When it's pressed, the image is changed (basically a checkbox) to denote a selection. When you scroll to the bottom ... then scroll back up to the top. The image is reverted to the original image.
This question is pretty similar to this:
Preserve Cell Image After Scrolling UITableView
And others. But, I can't seem to find a good answer. I understand that's it's reverting back to how the uitableview is setup when the cell goes off the screen. But, how do I save the changed image to the uitableview so when it scrolls it doesn't revert to the original?
Thanks in advance! =)
It's changing back because cells are reused. When your cell is going off the screen it is taken out of the view and put back into the reuse pool. Then you're getting it out of the queue again in cellForRowAtIndexPath and setting it back up as the default.
The question you linked to is exactly what you should follow. You should store the state of your cell in your view controller and then when you set it up again in cellForRowAtIndexPath you should load that state and set up the cell appropriately.
One simple way for your method would be to have an NSArray which you set up to be the same size as the number of rows in your table and then in that just store an NSNumber for each row which contains a boolean value on or off for your selection state. When the user toggles, toggle the value in the array and then in cellForRowAtIndexPath read that value and set it up appropriately.
I'm assuming the checkbox in your table view cell is changing state to a selected state because a user selected it. You shouldn't use UI elements to maintain the state of your app. That is, when the user taps the checkbox, you should use that event to somehow reflect that state change in a data object in your app. Then, when that cell needs to be displayed again, you configure it with the state you previously saved. This allows for things like cell reuse, and view unloading and is all-around a good habit.

get cursor on textfield

I need to get the cursor in textfiled but on the textfileddidbeginEditing i have to open the picker view for selection , so for that reason i need to resignFirtsresponder to the textfield ,inorder that picker view is visible .But by doing this the cursor gets disabled as i open the picker (and the keyboard gets hide by resignFirst responder).I want to show the cursor as because when user cliks on partilcuar textfield so by that cursor he can track on which textfield he is making the selection.
Hope i am clear with my question.
if you want the picker instead of keyboard, set the text fields inputView as the picker... so when you tap the text field the picker will pop up like keyboard and the textfield will show the cursor too.. no need to dismiss the keyboard and then show the picker..
If I understand your problem right, this is just an usability problem. I think you can solve this if you just add some other mechanism for showing the user which textfield is in editing-mode.
For example add an text-color to the TextField. If the user disable the UIPickerView set the text-color back to the normal state.

Change the setHighlighted for UIButton

I am using an UIButton to show and toggle a table-cell-item from read to unread.
I used a blue image as a background to show when an item was unread, and that worked, but figured that it would be better to use the setHighlighted feature, as it saves adding an extra image to the App. The code I use is as follows:
- (void)updateReadButton{
if(article.read.boolValue){
//[readButton setBackgroundImage:nil forState:UIControlStateNormal];
[readButton setHighlighted:FALSE];
[readButton setNeedsLayout];
} else {
[readButton setHighlighted:TRUE];
[readButton setNeedsLayout];
}
}
This works fine for the initial creation of the cell. But when the item is clicked and the detail-view is shown I toggle the 'read' value to 'true' and change the setHighlighted option to false of the UIButton in the cell, but it doesn't change when coming back from the detail view. Only when the cell is scrolling off the screen and recreated is the change reflected. How can I force a redraw of the button once I navigate to the detail view?
You may be able to accomplish the highlight by simply reloading the cell in question. Peek at UITableView's - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation and use it to reload the cell after setting the highlight.
I don't think the method setHighlighted: is the correct one. Here is the documentation:
Specify YES if the control is
highlighted; otherwise NO.
By default, a control is not
highlighted. UIControl automatically
sets and clears this state
automatically when a touch enters and
exits during tracking and when there
is a touch up.