I have following problem - if i select cell and then select empty space in tableWidget i can't again edit cell, i have to select another cell and again previous to be able edit it.
In vide i'm trying to edit second cell, but can't do this.
https://youtu.be/ibAFT1OkeHQ
I read about QTableWidget properties but did't find anything useful.
Found solution
QObject::connect(ui->tableWidgetData, &QTableWidget::clicked,
ui->tableWidgetData, QOverload<const QModelIndex&>::of(&QTableWidget::edit));
And on QTableWidget choose selection mode NoSelection.
Related
I want my table to be not selectable, so that only check boxes or radio buttons could be selected, but not the cell itself. Now I have:
How can I fix this?
Solutions for QTableWidget can help too.
QTableView *test = new QTableView();
test->setSelectionMode(QAbstractItemView::NoSelection);
gives the wanted result.
I want to make a list of n rows with m columns. Last column must contain a button which on clicking deletes the entire row which that button belongs to.
Click here to see my desired GUI.
I have already looked for wx.grid and didn't get any success.
My questions are
Can this be achieved by using wx.ListCtrl?. If yes then how?
Which is the best wx widget other than wx.grid to achieve this.
Any sample code or illustration will be appreciated.
Thanks
Currently I want to implement a widget to allow user to enable/disbale all provided options of a QSet. So i took a combobox and added selectable items. So far so good, but how I can change text displayed in combobox? Currently all my items have just ItemIsUserCheckable and ItemIsEnabled as enabled flags (ItemIsSelectable is not enabled), so text of ComboBox is always text of first item. Instead I want as text "Flag1, Flag 3, Flag6" if there multiple flags and user enabled Flag 1, 3 and 6. But setCurrentText and setEditText requiring setEditable(true) or an custom lineEdit. But using an lineEdit is changing appearance. So is there another way?
I had a similar problem a while back, I ended up 'solving' it by adding an extra item to my model that was first in the list and always set as the current item. I then updated it's text to say 'Select items...' or 'X item(s) selected' as appropriate.
I am using a QTableWidget and I have a requirement that the user is able to highlight specific text in a cell, but the cell contents should not change if the user accidentally erases or modifies some cell contents. I was thinking that the simplest way to accomplish this would be to just ignore any edits that occur when the user finishes editing a cell. Any ideas how to do this?
Using C++ 98 and QT
You can access the table widget items and modify their properties You want to disable the Qt::ItemIsEditable flag :
QTableWidgetItem* item;
item->setFlags(item->flags() & ~(Qt::ItemIsEditable));
A good way is to set the item prototype before inserting cells into the table. Right after creating the table
const QtableItem* protoitem = table->itemPrototype();
QtableItem* newprotoitem = protoitem->clone();
newprotoitem->>setFlags(item->flags() & ~(Qt::ItemIsEditable));
table->setItemPrototype(newprotoitem);
Now every new cell in the table will have the editable flag disabled. If the user double click it will not open the text edit in the cell.
ps: Do not delete newprotoitem afterwards.
This is late, but for follow-on searches:
The best way to do this is to subclass a delegate (QStyledItemDelegate is the least problematic - no abstract virtuals).
In the delegate, override 'setModelData()' to a stub. The editor will still come up, and you can still change its contents, but the edit won't 'take'. As soon as you leave the cell, it will revert to its original contents.
If you want to prevent the editor from accepting keys (QLineEdit), override 'createEditor()' in your delegate. Call the base class to create an editor, check its type, and then install an event filter on the editor to reject keypress/keyrelease events.
Return the editor in your override.
Works for me, although I did have to const_cast 'this' (to non-const) to install the event filter.
When clicking on QTableWidget cell, it selects only the cell. How to configure tablewidget, so that when click on a cell , the whole row will be selected which contains the cell?
It can be done using signal,slots. I'm curious is there standard way doing it?
Simply use setSelectionBehavior
QTableView * tmp = new QTableView();
tmp->setSelectionBehavior(QAbstractItemView::SelectRows);
http://doc.qt.io/qt-5/qabstractitemview.html#SelectionBehavior-enum