I am developing a recipe application using a QTableWidget to add the ingredients for a recipe. I use a button to add a row to insert a new ingredient. This works well but like many existing applications I would like to use the tab key to add a new row when the last column in the last row has the focus. I presume I must identify the tab key pressed and which column and row has the focus but I am not clear on how to do that.
The easiest way is to subclass the table widget and implement the closeEditor() function, which is called whenever a delegate signals that the editor is going to be closed, and is proposing the next action to do after closing.
Using the tab key, the EditNextItem hint is used, so it's enough to check for that flag, ensure if the current index is the last column of the last row, and then add a row before calling the base implementation method:
class TableWidget(QtWidgets.QTableWidget):
def closeEditor(self, editor, hint):
if hint == QtWidgets.QAbstractItemDelegate.EditNextItem:
current = self.currentIndex()
if (current.row() == self.rowCount() - 1 and
current.column() == self.columnCount() - 1):
self.insertRow(self.rowCount())
super().closeEditor(editor, hint)
Related
I have one web table, in this I want to delete particular record by clicking on record's delete button.
I got the value of row but I am not able to perform click on web button of particular row and also there is 2 buttons in one column.
How to click on delete icon of particular row?
You need to set a reference to the item within the specific row and then click on it - something like this:
Set oLink = Browser("myBrowser").Page("myPage").WebTable("myTable").ChildItem(iRow,8,"Link",0)
oLink.Click
You will potentially need to amend the "Link" and the number 8 in your own code. iRow represents the row you are trying to interact with.
Essentially what this code does is set an object reference to the first item of type "Link", in column 8 of the table, then uses a Click event to select it. If your delete icon is a WebButton, then replace "Link" with "WebButton" for example. The final 0 in the command tells UFT to select the first element matching the object type - you might need 1 if your two icons are in the same column of the table.
Let me know if that helped.
I'm using jqgrid with inline editing , when the user gets to the last cell inside a row , when he clickes on "tab" key he will be editing the next row - and if it does not exist a new row will be created.
I want to add a delete row function for the user , but still to have that row data inorder to send it later to the server as a deleted row.
I tried hiding the row , but then when the user "tabs" to the next row - it goes to the hided row - and i want it to go only to the not hided rows.
Is there a way to mark a row as deleted? and then when I generate the xml from the grid rows it will be a part of those rows? or is there a way to delete the row and save it's cells values , and be able to navigate throgh the grids line without going throgh the deleted line?
Any help will be appritiated!
Thank's In Advance.
To fix problem with editing of hidden row you can try to add class "not-editable-row" to the row which you hide.
$("#"+rowid).addClass("not-editable-row").hide();
If it will not help you will have to overwrite the default "TAB" behavior of jqGrid (see the question for implementation details)
Probably more easer way would be to use delRowData which delete a row from the grid without sending any information to the server. If you want to have your custom implementation of the "Delete" button in the navigator (see the example here). Inside of your onClickButton event handler you can save the contain of rows, which will be deleted, to some JavaScript array/object and then delete the row with respect of delRowData. So you can trace all delete operation, save deleted rows and send later all needed informations to the server.
Using Watir to regression test some changes: I want to 'click' a row in a typical old style web page menu, where the menu is a table of tables. In this particular example, the table cell contains the menu item, and the row, which only consists of the one cell, has an onclick handler. I thought I could
cell = browser.element_by_xpath("//div[#id='Menu']/descendant::td[text()='New!'")
and use the cell to get the parent row, but I get the message
c:/ruby/lib/ruby/1.8/rexml/parsers/xpathparser.rb:330:in 'Predicate': undefined
method `[]' for nil:NilClass (NoMethodError)
which makes no sense to me.
We really need more detail before before an answer can be given
Generally speaking there are a few ways to deal with tables. You can use absolute indexes to the row and column numbers if that will always be the same, but a lot of times that's not the case.
If there's known (unique) text on the row somewhere, and the column of the cell is known, then you can often work via using a regular expression to identify the row with the known (and unique) text, and then identify the needed cell via it's 'column' within the row.
browser.row(:text, /my search text/).cell(:index, 2) # 2nd cell in the row that contains text matched by the regex
try this
cell = browser.div(:id,'Menu').cell(:text,'New!')
cell.click
and, maybe you lost closing ']' ?
cell = browser.element_by_xpath("//div[#id='Menu']/descendant::td[text()='New!']")
I would like to be warned when user selects the whole row in a wxGrid but I do not see an event that handles this.What is the best way to do it?
You can do this using EVT_GRID_RANGE_SELECT, and then check that the range is a single row when the handler is called.
For example, in the GridSimple.py wxPython demo, put the line in SimpleGrid.__init__
self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnSelectRange)
And then add this to see which cells were selected.
def OnSelectRange(self, evt):
print "on select range", evt.GetTopLeftCoords(), evt.GetBottomRightCoords()
From this you can determine whether the selection was one that you're interested in.
Actually, I figured it out. There are events like EVT_GRID_LABEL_LEFT_CLICK and then I test event.GetCol() == -1, to make sure the click is on a whole row, not a whole column.
I'm trying to implement inline inserting in a JQGrid. My approach thus far is:
Use addRowData to put a blank row at the end with ID=-1
Use editGridRow to edit that row
Detect on the server that this update is actually an insert because ID=-1, and return the new ID value
Suprisingly, this rube goldberg scheme works pretty well. To make it seamless, though, I'd like to silently update the ID of the row that was just added, so that the user can continue to edit the other columns. I'd rather not do a grid.trigger("reloadGrid"), because I lose focus on that row.
I've tried
grid.setRowData(-1, { MyPrimaryKeyField: newID });
but that doesn't work (it still thinks the row's ID is -1). Is there an easy way to change the primary ID of a row without reloading the whole grid?
Actually you can't change grids primary row Id by "setRowData",
but there is a simple way to do it :
$("#-1").attr('id',newId);
;-)
You could work around this by making an AJAX call to do the insert and return the new ID. Once you have the ID, call reloadGrid and then select the row using the newly returned ID. You would want to also put up a spinner while you are doing this so the user knows your page is busy. Not quite what you are asking for but it should meet your needs.