How to set QTableView as a cell of QTableView - qt

I have QTableView - mainTableView, in some cells of which I need to show another QTableView - cellTableView.
Actually I found 2 ways:
1) Use pTableView->setIndexWidget
2) Use pTableView->openPersistentEditor and implement an ItemDelegate.
I have tried both ways and the problem is just the same. When I use an ItemDelegate without openPersistentEditor everything works good. Otherwise, as I understand, there is a problem with focus and with HeaderView of the table in a cell.
I would like to solve the following problems:
sometimes instead of a HeaderView of cellTableView, background of mainTableView is shown.
When I press a key on a cell of cellTableView, editor for this cell is not opened but the pressed symbol is set to the cell (editor opened->editor receives "FocusOut" signal->editor is closed, pressed value is stored to the cell).
With space key or double click editing works good.
Someone could me explain how to solve this behavior?

I have found this solution.
http://qtadventures.wordpress.com/2012/02/04/adding-button-to-qviewtable/
For my case I need even less and it works just great!
I switch a cell to the edit mode manually, when the cell is selected.

Related

Delaying the opening of a NSPopUpButton

I've encountered the same problem as this one:
This one.
It has never been answered so far. In two words:
When you place a NSPopUpButtonCell in a NSTableView, the popUp opens before the selection in the tableView has changed.
If the menu of the popUp relies on the selection of a row of the tableView, it will be updated too late.
Solution 1: differ the opening of the popUp with a block which calls [super] a few nanoseconds later. But I don't know which method I must override.
Solution 2: use other bindings that I'm currently using (the popUp contains the NSSet of the entity selected in the table, I'm using a different controller, not the table's one, and I bind its content set to myTable.selection.theSet.
Is there something else I could do? Thanks !
Yes, if you use a view-based tableView, you can bind the popUp through the cellView it’s inside (like the other table objects you bind in this mode), and so it’s completely unambiguous and doesn’t depend on the selection.
In view-based mode, each cell in each row have is assigned an ‘objectValue’ from your original data, so you can bind directly to it, like ‘objectValue.popUpContents’.

Enabling richt text font (RTF) in QComboBox

I've to deal with a scientific application and thus have to use RTF at many place (think about displaying units with exponents mainly).
I've implemented a delegate to deal with tables and drop box and it works mostly fine. (implementation : http://pastebin.com/FuCbGqkY , header : http://pastebin.com/D6hxeWdF ).
However, I've been into a major issue : it looks like the "button" part of the QComboBox is not rendered with the delegate (it only applies to the drop down box). Is there any way to have the text in the combobox when it's not dropped displayed correctly ? If not, what do I have to do ? Subclass and overwrite paint method ? Looks like a lot of pain and basically it makes the delegate useless.
Any clue ?
Consider QComboBox::lineEdit() method. You can try to apply your changes to the QLineEdit directly if it's possible. Otherwise you can subclass QLineEdit and change its behaviour to what you want, and then insert it using QComboBox::setLineEdit. Maybe you will need to make the combo box editable in order to use this.

How to implement excel-like formula editor in XtraGrid?

I'm working on complicated system, which allows some values in grid to be calculated by formulas.
Right now I have textbox control above grid.
It works in this way:
When you start editing inside in-place editor and first symbol is '=' - focus is moved to that textbox control above.
At this moment grid is made readonly, and when user clicks on grid cells - coordinates of the clicked cell are passed to formula editor, so it can add links to formula. When you press Enter or Esc in text editor - formula is being written to underlying dataset and grid is made editable back.
The goal:
I want this too look more like Excel grid. Don't like focus to jump somewhere outside.
Is it possible to keep editor open and at the same time allow user to click anywhere on grid? So, all formula editing will be performed inside inplace editor?
Right now, there's no event to disallow closing editor. If I use 'ValidateEditor' event - it doesn't even allow to use scrollbars.
Is there a way to keep editor open and leave navigation working?
Seems I have found way round that myself.
I handle ValidatingEditorEvent, and if edit value starts with '=' I set boolean flag in my control. Also, I remember text before and after cursor position, and cell coordinates (FocusedRowHandle, FocusedColumn).
When I receive Click event, I get clicked cell coordinates and if boolean flag is set - I focus previous cell, activate editor and add what I need to inpalce editor.
Seems to work fine.

Show Editors for All Cells in Row in QTableView

I would like to display editors for all cells in a row when a user begins editing any cell in a QTableView. I have made several attempts but I cannot obtain the correct behaviour.
The only way to open multiple editors is by QAbstractItemView::openPersistentEditor() - attempts to successively call QAbstractItemView::edit() results in only one editor.
I cannot use signals such as clicked() and doubleClicked() from QAbstractItemView to invoke editing, because then it would not respect the edit triggers of the view.
There appears to be no "editing complete" signal. I would like to connect this signal to a slot that calls closePersistentEditor() for cells in the editing row.
Any suggestions would be appreciated.
Thanks!
I hate to be the bearer of bad news, but I can't think of any easy way to do what you want. I can think of a couple of options, each more painful than the last:
You could create a delegate that always shows the editors, and when the user changes the selected row, set that delegate for the newly selected row, and the original delegate for the deselected row.
You could try inheriting from the table view, and overriding the behavior for drawing the appropriate items for everything in the given row. I have no idea how hard this would be, but I doubt it would be trivial.
You could create your own view to display the model. I've never done this, and I'd hate to think about all that would be required to "complete" support the models. However, to match with one specific model, you might be able to get away with it.

How can I tell a QTableWidget to end editing a cell?

I'm showing a popup menu to select some values in a QTableWidget. The lowest item is a "Modify list" entry, when I select it a new window should automatically appear and the QComboBox should vanish and the cell return to a Qt::DisplayRole state.
Now Qt has all those nice API-calls like QTableWidget.edit() and QTableWidget.editItem(), what I'm really looking for is a QTableWidget.endEditing(), preferably without specifying the index of the cell, though I could get that using this call:
table.currentIndex()
… but I don't know if I can guarantee that the current cell is the cell being edited at all times.
Is there an API to close those kind of editors?
QTableWidget inherits 19 public slots from QWidget. One of those is setDisabled(), which should disable input events for that widget and all of its children.
I would try:
table.setDisabled( true );
table.setDisabled( false );
Although you said it does not work for you, there is an alternative method:
If you don't like that (the table loses focus, I believe), you can try using EditTriggers. For example:
table.setEditTriggers( QAbstractItemView::NoEditTriggers );
table.setCurrentItem(None) is what worked for me. (Don’t forget to block signals if you use some cellChanged/itemChanged slot function.)
This is with PyQt. For C++ I think replace None with NULL.
You may be able to use QTableWidget.closePersistentEditor() to close the editor. However, QAbstractItemView.closeEditor() may be closer to what you want, especially since you seem to be comfortable with the QModelIndex-based API and are already using a custom editor widget.
In my case, none of the options worked properly. So, I figured: I need to send the key press event to the line edit itself. The following works with QTreeView but probably does work with any other view or widget that opens a line edit to edit cells.
QWidget* editingWidget = treeView->findChild<QLineEdit*>();
if(editingWidget)
{
QKeyEvent keyPressEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
QApplication::sendEvent(editingWidget, &keyPressEvent);
QApplication::processEvents(); // see note below
}
In my case, I wanted to start editing another field directly when having finished editing one item. That is why I put processEvents there, in most cases you can probably remove that line.
PS: yeah, it's C++, but should be easily adaptable to Python. I found this thread when I searched for the C++ solution, so maybe it helps anyone else, too.
I can't speak for list widgets. But, I got here trying to do something similar.
I was double-clicking a cell, and based on the column, bringing up a sub-form with a list, then when that was closed move to the next appropriate column based on the value selected.
My problem was I could get the value in the cell and "select" the next appropriate cell, but the original cell stayed selected in edit mode!
It finally dawned on me that my double-click was selecting the cell, ie. editing.
A single-click selects the cell but doesn't open an edit mode.
Side note: Never could get that sub-form to act truly modal, so I created a loop in the calling form: while the sub form was visible, with the only code being app.processEvents()

Resources