View Full Version : Disable or lock a QTableWidget
grub87
15th July 2009, 20:59
Hi i'm working with a QTableWidget and want to disable or lock the edition of it. I know that a QTableView would do the trick, but i'm working with an open source project that has this "issue", because this table is big, it would take me a lot of time to start working with a QTableView. THANKS IN ADVANCE
The most straight forward way, for the whole view:
QAbstractItemView::setEditTriggers()
QAbstractItemView::NoEditTriggers
A bit more tedious way, adjusting the flags for individual items:
QTableWidgetItem::setFlags()
Qt::ItemIsEditable
grub87
16th July 2009, 15:03
Hi thanks for your advice, but i don't know how to implement your answers could you give a head start on that please.
grub87
16th July 2009, 15:28
I thought i would be a property or function of my QTableWdiget object, for example:
object->setEditTriggers(); //This tells me that inside the () goes a EditTriggers
object->editTriggers();
Yes, it is a property. There is a getter that returns the current edit triggers in use, and there is a setter which you can use to change the edit triggers. Don't you think the setter would perhaps take a parameter, like suggested by your compiler? Not to be rude, but perhaps it's time to get back to your favourite C++ book for a while?
PS. Here's the link to the documentation once more, because the first one seemed to be broken: QAbstractItemView::editTriggers
grub87
16th July 2009, 15:46
Yes every object has a getter and a setter, the setter obviously needs a parameter, but i was refering to how you put the EditTriggers, i put it like this:
ui.diariostableWidget->setEditTriggers(QAbstractItemView::EditTriggers(0) );
But it doesn't work.
That should work, but for better readability (and safer code) you should use the corresponding enum value called "no edit triggers".
grub87
16th July 2009, 17:02
Hi again, i tried to use the NoEditTriggers like this but it doesn work either:
ui.diariostableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers) ;
But what do you mean by "doesn't work"? Please try to be more specific.
grub87
16th July 2009, 17:06
I can still edit the items of the table
Works fine for me:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTableWidget table(4, 4);
// uncomment the following line and the table can no more be edited:
// table.setEditTriggers(QAbstractItemView::NoEditTri ggers);
table.show();
return app.exec();
}
grub87
16th July 2009, 17:27
I think it doesn't work because in the part of the options of tha visual form in editTriggers the options of editing with double click was checked, i noticed the existance of this option until now :o, that's why anything i put in the .cpp didn't work. THANKS FOR ALL THE HELP!!! :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.