[Interest] QComboBox inside in QTableWidget: How to disable mouse scrolling of QComboBox?

Muthulingam Ammaiappan muthulingam.a at gmail.com
Tue Feb 7 10:59:37 CET 2012


Hi Friends,

I have QTableWidget... it has "QComboBox" as a cellWidget in one of it
column...

I wanted to disable the ScrollEvent of QComboBox... so when cursor is on
top of the QComboBox ,if user try to do the Mouse Scroll,then it should not
change the index....

To achieve this, I just implemented the "eventFilter" in TableWidget
class.... but still ScrollEvent is working...

can anyone please help me to fix this problem...?


Thanks & Regards,
Muthu

code snippet:

TableWidget::TableWidget(QWidget *parent, MainWindow *mainwindow)

    : QTableWidget(parent)

{

        versioncombo->setFocusPolicy( Qt::StrongFocus);

    versioncombo->installEventFilter( this );

 }



bool TableWidget::eventFilter(QObject *obj, QEvent *event)

{

    if(event->type() == QEvent::Wheel &&

           qobject_cast<CustomComboBox*>(obj))

        {

            if(qobject_cast<CustomComboBox*>(obj)->focusPolicy() ==
Qt::WheelFocus)

            {

                event->accept();

                return false;

            }

            else

            {

                event->ignore();

                return true;

            }

        }

        return QWidget::eventFilter(obj, event);

}




CustomComboBox::CustomComboBox(QWidget *parent)

    : QComboBox(parent)

{

    setEditable (false);

    setFocusPolicy(Qt::StrongFocus);

}



void CustomComboBox::focusInEvent(QFocusEvent*)

{

     setFocusPolicy(Qt::WheelFocus);

}

 void CustomComboBox::focusOutEvent(QFocusEvent*)

{

     setFocusPolicy(Qt::StrongFocus);

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120207/d4f2b17e/attachment.html>


More information about the Interest mailing list