[Qt-interest] selection with widgets in a QTreeWidget

Malyushytsky, Alex alex at wai.com
Wed Jun 3 04:58:15 CEST 2009


When you construct your combobox, install event filter on it.
You will need to modify the code below to use  QTreeWidget::setCurrentItem ( QTreeWidgetItem * item ),
But I think the root problem is the same - combobox should set the proper cell/item current.
This does not happen, if one of the comboboxes other than QTableWidget or QTreeWidget has focus.


>From initialization of comboboxes

                comboScaleX->setFrame ( false );
                comboScaleX->setFocusPolicy ( Qt::StrongFocus );

                table->setCellWidget( 0, 4, comboScaleX );

                comboScaleX->installEventFilter( this );


In the event filter you call setCurrentCell

bool commandViewUi::eventFilter(QObject* _obj, QEvent *_event)
{
 .............

        else if ( _event->type() == QEvent::FocusIn)
        {
                if ( _obj->inherits( "QComboBox" ) )
                {
                        int row=0;
                        int col=-1;
                        QComboBox* combo = static_cast<QComboBox *>( _obj);
                        QTableWidget* table=NULL;

                        if ( combo == comboScaleX )
                        {
                                col=4;
                                table = guiWidget->tableXYPlot;
                        }
                        else if ( ( row = rowCurveColorComboBox ( combo ) ) > -1)
                        {
                                table = guiWidget->m_pCurvesProperties;
                                col = COL_CURVE_COLOR;
                        }

                        if( table && col > -1 && row > -1)
                        {// passing event to QTableWidget

                                table->setCurrentCell ( row, col );

                                return false;
                        }
                }
        }

}

Hope this helps,

 Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Kishore
Sent: Tuesday, June 02, 2009 9:33 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] selection with widgets in a QTreeWidget

I am using a QTreeWidget and am inserting combo boxes in certain columns of
the view. But I am facing one serious issue currently.

First, when I click on an embedded combo box widget, the associated row gets
selected. However, once after clicking on the widget clicking on any other
widget of another row does the cause the selection to change to that row. For
that to happen, i have to first click on any place that does not contain a
widget.

How can i solve this? I require that the corresponding row always gets
selected so that the correct currentItem() is returned.
--
Cheers!
Kishore
_______________________________________________
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