Hi @Qt_Python-Learner,
I know this issue is quite old, but it might still help somebody. I managed to limit the number of visible items in a Fusion style dashboard using this class:
class ComboBox(QtWidgets.QComboBox):
""" Modify default class of PyQT5 combobox. """
def __init__(self, parent=None):
super(ComboBox, self).__init__(parent)
# setMaxVisibleItems only works if the box is editable
# this creates a line edit that we need to overwrite
self.setEditable(True)
self.setMaxVisibleItems(15)
# overwrite default line edit by an invisible one
self.lineEdit().setFrame(False)
self.lineEdit().setReadOnly(True)
def showPopup(self):
""" Show pop-up. """
# set index of selected choice to highlight it
text = self.lineEdit().text()
index = self.findText(text, QtCore.Qt.MatchFixedString)
self.setCurrentIndex(index)
# show pop-up
super().showPopup()
# add vertical scroll bar
self.view().setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
# increase the width of the elements on popup so they can be read
self.view().setMinimumWidth(self.view().sizeHintForColumn(0))
I hope this can help you or others.
Cheers,
Alba