Detecting hover over QComboBox items in PyQt6/PySide6

42 views Asked by At

Here is an example code

from PySide6.QtCore import QEvent
from PySide6.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout
import sys


class MainWidget(QWidget):

    def __init__(self):
        super(MainWidget, self).__init__()
        
        self.combo_box = QComboBox(self)
        self.combo_box.addItem('Item 1')
        self.combo_box.addItem('Item 2')
        self.combo_box.addItem('Item 3')
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.combo_box)

        self.combo_box.installEventFilter(self)


    def eventFilter(self, obj, ev):
        if ev.type() == QEvent.Enter:
            print('here is suppossed to be item that I hovered over')
        return super().eventFilter(obj, ev)


app = QApplication(sys.argv)
window = MainWidget()
window.show()
app.exec()

What I want to do is to access the item (as an object) of the dropdown list of combo box, when hovering over it.

For example - I click on the combox, I hover my cursor over "Item 2" and I can apply animation of color change transition to it (which is not possible through stylesheets).

I've tried researching how to access QComboBox items'/children' signals with **highlighted**however with no luck

0

There are 0 answers