PyQt5 Combobox HorizontalScrollBar overlaps last item

49 Views Asked by At

PyQt5 HorizontalScrollBar on combobox overlaps last item

This is without scrollbar

This is after combo.view().setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

And also if i try ScrollBarAsNeeded i get this bug

Please help me to fix that issue

Thanks!

I found (Allow horizontal scrolling in a QComboBox)

It helped me a lot but if combo has 2-4 items it's starting overlap last item.

And if combo.view().setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) then VerticalScrollBar also appears but his default policy is ScrollBarAsNeeded as i know

Edited...

This a pretty simple example of issue:

import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *


class Window(QMainWindow):

    def __init__(self):
        super().__init__()
        self.combo_box_issue = None
        self.combo_box_good = None
        self.setWindowTitle("Python ")
        self.setGeometry(100, 100, 600, 400)
        self.UiComponents()
        self.show()

    def UiComponents(self):
        # bad combo
        self.combo_box_issue = QComboBox(self)
        self.combo_box_issue.setFixedWidth(300)
        self.combo_box_issue.setGeometry(170, 100, 120, 30)
        self.combo_box_issue.setEditable(True)
        view = QListView(self)
        geek_list = ["Geek", "Geeky GeekGeeky GeekGeeky GeekGeeky"]
        self.combo_box_issue.addItems(geek_list)
        self.combo_box_issue.setView(view)
        view.setTextElideMode(QtCore.Qt.ElideNone)
        view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        # good combo
        self.combo_box_good = QComboBox(self)
        self.combo_box_good.setFixedWidth(300)
        self.combo_box_good.setGeometry(170, 200, 120, 30)
        self.combo_box_good.setEditable(True)
        view = QListView(self)
        geek_list = ["Geek", "Geeky GeekGeeky GeekGeeky GeekGeekyGeekGeeky GeekGeeky GeekGeekyGeekGeeky GeekGeeky GeekGeekyGeekGeeky GeekGeeky GeekGeeky"]
        self.combo_box_good.addItems(geek_list)
        self.combo_box_good.setView(view)
        view.setTextElideMode(QtCore.Qt.ElideNone)
        view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)


App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())

So if i clicked a bad combo first time i got this. But if i clicked one more time i got this. HorizontalScroll overlaps last item of combo

And when i use policy ScrollBarAsNeeded i got this

Why it's starting overlaps? Why verticalscrollbar is born?

0

There are 0 best solutions below