bool MyWidget::eventFilter(QObject *obj, QEvent *event) { // Disable mouse wheel scrolling in the QComboBox if (obj == ui->comboBox && event->type() == QEvent::Wheel) { return true; } return QObject::eventFilter(obj, event); } // Install event filter on QComboBox ui->comboBox->installEventFilter(this);
bool MyWidget::eventFilter(QObject *obj, QEvent *event) { // Change the text alignment in QComboBox if (obj == ui->comboBox && event->type() == QEvent::Show) { QComboBox* comboBox = qobject_castIn this example, we override the eventFilter method to intercept the Show event of the QComboBox. We then obtain the view of the QComboBox and change the text elide mode and text alignment. This code changes the alignment of the text in the dropdown list of the QComboBox to align right. Package library: Qt5Core.(obj); comboBox->view()->setTextElideMode(Qt::ElideRight); comboBox->view()->setTextAlignment(Qt::AlignRight); } return QObject::eventFilter(obj, event); } // Install event filter on QComboBox ui->comboBox->installEventFilter(this);