Hi..
Can i create a table with certain cells with a "read only" property...??? i did look up the documentation of QTableWidget but did not find any answers... Any clues anyone...?? thanks...
Hi..
Can i create a table with certain cells with a "read only" property...??? i did look up the documentation of QTableWidget but did not find any answers... Any clues anyone...?? thanks...
Each cell of QTableWidget is an object of QTableWidgetItem. You can use setFlags function of QTableWidgetItem class to make the cell read only.
Mithin
www.mithin.in
thanks mate.... and also i wanted to know whether i can include a spinbox or a combobox in a cell...
got it..!! thanks all...!!
thats exactly what i cannot think of..!!![]()
I checked the documentation for setting the flag values but the problem is all of them are for enabling them...none of them are to disable them...!! i triedandQt Code:
exht->setFlags(Qt::ItemIsEditable(false));To copy to clipboard, switch view to plain text modeand all possible combinations i could think of(Now i don't know if the code is right or no) but its just not helping...!!!Qt Code:
exht->setFlags(Qt::ItemIsEditable = 0);To copy to clipboard, switch view to plain text modeplease help...!!!
Use bitwise operators:
Qt Code:
item->setFlags(item->flags() & ~Qt::ItemIsEditable);To copy to clipboard, switch view to plain text mode
J-P Nurmi
frankiefrank (2nd January 2012)
i went through the tutorial...and now i can include a spinbox or a doublespinbox using delegates... but now what i cannot understand is what if i wanted to include the spinbox(or any other widget) in just a few cells(keeping the other cells normal) instead of the all the cells..??? will have to make another delegate to implement the QTableWidgetItem ...?? or is there any way i can apply the delegate to just a few cells instead of making a model of the entire table and then including the delegates..??? please advice... thanks...
There are several ways to achieve that. One extremely simple but not that dynamic way would be to check the column and row number in createEditor(). For example:
A bit more flexible way would be to use user roles to store the information:Qt Code:
{ if (index.column() == 3 && index.row() > 2) { ... return customEditor; } return 0; // or return QItemDelegate::createEditor(parent, option, index); }To copy to clipboard, switch view to plain text mode
You can also consider using item/cell widgets as already suggested, but just be aware that they don't really integrate to the model-view framework. They're just something laid by hand on top of views.Qt Code:
tableWidgetItem->setData(Qt::UserRole, true); { if (index.data(Qt::UserRole).toBool() == true) { ... return customEditor; } return 0; // or return QItemDelegate::createEditor(parent, option, index); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
Bookmarks