[Qt-interest] QTreeWidgetItem: setFlags only on some columns

Malyushytsky, Alex alex at wai.com
Fri Mar 6 04:20:16 CET 2009


I guess it is possible by using setItemDelegateForColumn() or setItemDelegate().

( QAbstractItemDelegate * delegate ).
Override createEditor in your QItemDelegate subclass.

Either prevent all editors to be created
QWidget* MyItemDelegate::createEditor( QWidget *parent,
        const QStyleOptionViewItem &option, const QModelIndex &index) const
{
 return NULL;
}
and  set delegate with setItemDelegateForColumn for columns you don't want to be editable.

Or allow/prevent creation editor in the createEditor depending on column.
This way is a bit more complex, but it will also allow you to customize editors for each column ( for example set validators):

QWidget* MyItemDelegate::createEditor( QWidget *parent,
        const QStyleOptionViewItem &option, const QModelIndex &index) const
{
        Q_ASSERT( tableSource && makeDialog ); // init MUST be called already

        QWidget* w = NULL;

        QTableWidgetItem* item = treeWidgetSource->itemFromIndex ( index );
        if( item )
        {
// where treeWidgetSource - your QTreeWidget
                int column = item->column();

                if( column == 1 )
            {
                        w = QItemDelegate::createEditor( parent, option, index); // set validator if you want here
             }
                else
                  w=NULL;
..................
      }

return w;

}

Code is not tested, written on the fly, but you should be able to make it work.

Regards,
     Alex Malyushytsky


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Giacomo S.
Sent: Thursday, March 05, 2009 6:28 AM
To: qtInterest
Subject: [Qt-interest] QTreeWidgetItem: setFlags only on some columns

Hi to all!

Is it possible to set editable only some columns of a QTreeWidgetItem
(that is, setting different flags on different columns?)

Thanks

giacomo

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list