PDA

View Full Version : How to set a column readonly in qtablewidgetitem



ashukla
23rd October 2007, 08:43
Respected Sir/mMe,

Sir/mMe i am facing problem in setting a column readonly in qt4. I think i have to use setFlag() function but what value is to be set as parameter to make column readonly i can't
understand.
Sir/mMe kindly inform me if i am right then what parameter to set or any other way to be used to set it readonly

Thanking You All,

jpn
23rd October 2007, 09:02
You can pass an OR combination of flags, like "Flag1 | Flag2". Pass any combination without Qt::ItemIsEditable (http://doc.trolltech.com/latest/qt.html#ItemFlag-enum).

ashukla
23rd October 2007, 09:50
You can pass an OR combination of flags, like "Flag1 | Flag2". Pass any combination without Qt::ItemIsEditable (http://doc.trolltech.com/latest/qt.html#ItemFlag-enum).
QTableWidgetItem *__colItem = new QTableWidgetItem();
__colItem->setText(QApplication::translate("schedulePlaylist", "Playlist Name", 0, QApplication::UnicodeUTF8));
__colItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt ::ItemIsDragEnabled|Qt::ItemIsDropEnabled|Qt::Item IsUserCheckable|Qt::ItemIsTristate);
playlistTable->setHorizontalHeaderItem(0, __colItem);

I am using above but It is not working!

nile.one
23rd October 2007, 09:53
you don't have to pass all of the flags. just try to disable Qt::ItemIsEditable flag:
__colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);

ashukla
23rd October 2007, 12:30
you don't have to pass all of the flags. just try to disable Qt::ItemIsEditable flag:
__colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);

I am using as follows;
but it is not working!
QTableWidgetItem *__colItem = new QTableWidgetItem();
__colItem->setText(QApplication::translate("schedulePlaylist", "Playlist Name", 0, QApplication::UnicodeUTF8));
__colItem->setFlags(__colItem->flags() &~ Qt::ItemIsEditable);
playlistTable->setHorizontalHeaderItem(0, __colItem);

mchara
23rd October 2007, 13:26
Qt::ItemIsSelectable|Qt::ItemIsEnabled should be enought,

You should set those flags also for items inserted to widget, not only to headerItem.

Timith
8th November 2007, 14:23
QTableWidget *myTableWidget = new QTableWidget;

...filling myTableWidget with QTableWidgetItems ...

myTableWidget->setEditTriggers(QTableWidget::NoEditTriggers);