[Qt-interest] QTableWidget: how to make read-only certain columns

Israel Brewster israel at frontierflying.com
Mon Apr 6 18:24:12 CEST 2009


On Apr 5, 2009, at 3:45 PM, Miguel Cardenas wrote:

> Hi
>
> I need to make read-only full columns, not specific cells... am  
> working on a database report generator that will allow to modify  
> some columns (a signal will update the record), but a few ones  
> should remain untouched (id, item code, etc).
>
> A solution may be making read-only every cell from every column at  
> every line, but it should consume more processor than a single call  
> for a whole column...
>
> Lets see what say other users about this...
>
> Thanks for your help!

I'm curious - if you are working with databases, why are you using a  
QTableWidget rather than a table mode/QTableView pair? It seems to me  
the later would save you the (admittedly small) hassle of having to  
use signals/slots to update records. At any rate, one possibility I  
can think of is that you might try making a custom QItemDelegate which  
you assign to the columns you want read-only in which you have defined  
the createEditor function to return either nothing (probably the best  
if it actually works, but  I could see this potentially causing  
crashes), or else a read-only text entry, or perhaps even a label or  
the like (again, not sure if that would work). This comes with the  
caveat that I have only tried such things with QTableViews (not  
widgets) and I have not tried this specific application. I am also  
fairly certain I saw an example of doing something like this in the  
documentation (although it might have been for QSqlQueryModel and/or  
QSqlTableModel rather than for a QTableWidget), but a quick search  
isn't turning it up at the moment, so I'm not sure. Good luck.

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
> Miguel
>
> On Sun, Apr 5, 2009 at 2:02 PM, AngelWarrior <srikanth.bemineni at gmail.com 
> > wrote:
> void QTableWidgetItem::setFlags ( Qt::ItemFlags flags )
>
> use the Qt::ItemIsEditable
> I did not find the a unset flag hope somebody from qt answers this.
>
> One more trick is use setCellWidget() in QTableWidget to a QlineEdit  
> and make the lineEdit as readonly.This way you can make some cells  
> editable and some not.
>
> On Sun, Apr 5, 2009 at 1:44 PM, Miguel Cardenas  
> <mfcardenas at gmail.com> wrote:
> Hello list
>
> One question, is it possible to make read-only certain columns in a  
> QTableWidget? Didn't find something like this in the documentation...
>
> Thanks
>
> -- 
> Miguel Cardenas
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
>
> -- 
> _/\_
> With Regards
> SB Angel Warrior
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
>
> -- 
> Miguel Cardenas
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090406/874eb508/attachment.html 


More information about the Qt-interest-old mailing list