View Full Version : QTableWidgetItem setflags ..strange behavior
gab74
6th December 2011, 18:20
Developing on QT 4.2.3
I try to set an item of a table not editable:
QTableWidget *mytable;
QTableWidgetItem myvalue1;
myvalue1 = mytable->item(0,1);
2 ways
if i try:
myvalue1->setFlags(myvalue1->flags() | Qt::ItemIsEditable);
doesen't work.
if i try
// myvalue1->setFlags(Qt::ItemIsEditable);
this works.
Why this ???
Second Problem is that i want to unset the flag not editable,
but if i try
myvalue1->setFlags(myvalue1->flags() & ~Qt::ItemIsEditable);
This doesen't work.
Santosh Reddy
7th December 2011, 01:01
Looks like you are using the flags the opposite way, check this out
QTableWidget *tableWidget = new QTableWidget;
QTableWidgetItem *item = new QTableWidgetItem("My Item");
Qt::ItemFlags flags;
tableWidget ->setRowCount(1);
tableWidget ->setColumnCount(1);
tableWidget ->setItem(0, 0, item);
// set the item editable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable | Qt::ItemIsEditable; // set the flag
item->setFlags(flags);
// set the item non-editable (view only), but still selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags |= Qt::ItemIsSelectable;
flags &= ~Qt::ItemIsEditable; // reset/clear the flag
item->setFlags(flags);
// set the item non-editable (view only), and non-selectable
item = tableWidget->item(0, 0);
flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags);
gab74
7th December 2011, 09:34
Thank you !!! Very much I understand my errors with your code !!
I notice only a strange thing...
I've a table and a button, when clicks on the button the data in the rows is sent to the software.
Using the flag
// set the item non-editable (view only), and non-selectable
this works well but if i click on the row, even if it is not selectable and editable,
the item value are always set, and received by the software, when i click the button.
Is there a way to discharge the value sent from an unselectable and editable item ?
Santosh Reddy
9th December 2011, 01:09
It is hard to suggest as you have not mentioned about the slot connected to button click, what is does and how it gets data from table?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.