Set column as not editable in QTableWidget
-
@connect(ui->widget,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(column_check(int,int)));
void Saleorder::column_check(int row,int column)
{
QTableWidgetItem* itemtot=ui->widget->item(row, 9);if( column == 9 ) { if (itemtot && !itemtot->text().isEmpty()) { itemtot->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); } }
}@
i tried this but the program is crashed.
Any one help me solve the problem.
Is there is any other way to achieve to make the entire column as not editable
Thanks in advance
-
check "this":http://qt-project.org/forums/viewthread/16254/.
-
@
Qt::ItemFlags Saleorder::flags( const QModelIndex &index) const
{
Qt::ItemFlags flags = QSqlTableModel::flags(index);
if (index.column() == 9 )
flags &= ~Qt::ItemIsEditable;
return flags;
}@i use this but it displays the below error message.
saleorder.cpp:98: error: cannot call member function 'virtual Qt::ItemFlags QSqlTableModel::flags(const QModelIndex&) const' without object -
[quote author="Vidhya" date="1343736279"]
i use this but it displays the below error message.
saleorder.cpp:98: error: cannot call member function 'virtual Qt::ItemFlags QSqlTableModel::flags(const QModelIndex&) const' without object[/quote]Read the compiler message.
flags is not a static function and thus needs an object to be called from. So this:
@
Qt::ItemFlags flags = QSqlTableModel::flags(index);
@
is not valid code.
If saleorder is derived from QSqlTableModel (which i'd doubt) you can do this:
@
Qt::ItemFlags flags = flags(index);
@
otherwise you need a QSqlTableModel object
@
Qt::ItemFlags flags = someQSqlTableModelObject.flags(index);
//or
Qt::ItemFlags flags = someQSqlTableModelObjectPointer->flags(index);
@
Maybe this will work in your case:
@
Qt::ItemFlags flags = ui->widget->model()->flags(index);
@ -
try it :
// Qt::noItemFlags disable all flags , and u can add the flags again ;
@
void Saleorder::column_check(int row,int column)
{
if (!ui->widget->item(row, 9)->text().isEmpty())
{
ui->widget->item(row,9)->setFlags(Qt::NoItemFlags|Qt::ItemIsSelectable|Qt::ItemIsEnabled);
}
}
@