Khi tôi tìm thấy câu hỏi này, khi tôi cố gắng tìm ra giải pháp (về cơ bản) cùng một vấn đề: Trong trường hợp của tôi, tôi muốn có QComboBox trong QScrollArea trong pyside (python QT lib).
đây định nghĩa lại tôi QComboBox lớp:
#this combo box scrolls only if opend before.
#if the mouse is over the combobox and the mousewheel is turned,
# the mousewheel event of the scrollWidget is triggered
class MyQComboBox(QtGui.QComboBox):
def __init__(self, scrollWidget=None, *args, **kwargs):
super(MyQComboBox, self).__init__(*args, **kwargs)
self.scrollWidget=scrollWidget
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, *args, **kwargs):
if self.hasFocus():
return QtGui.QComboBox.wheelEvent(self, *args, **kwargs)
else:
return self.scrollWidget.wheelEvent(*args, **kwargs)
đó là callable theo cách này:
self.scrollArea = QtGui.QScrollArea(self)
self.frmScroll = QtGui.QFrame(self.scrollArea)
cmbOption = MyQComboBox(self.frmScroll)
Nó là cơ bản emkey08's answer trong link Ralph Tandetzky pointed out, nhưng lần này trong python.
Nguồn
2017-04-18 08:33:17
Tôi cũng đã thay đổi chính sách tập trung của combobox để nhấp. Điều này đã giúp quá. Cảm ơn! –
Nhưng QComboBox bị STILL FOCUSED nếu tôi lật qua nó. Tại sao? Làm thế nào để ngăn chặn nó? Tôi không muốn vô hiệu hóa tiêu điểm mà chỉ tập trung vào bánh xe. – 18C