[Python] How do I set QComboBox height?

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    So i've been working with pyqt5 and i'm trying to set the height (size not position) of a qcombobox. Not the drop-down list, the actual box. I've tried everything and nothing seems to work. setFixedSize only changes the width of the box and then its y position on the main window instead of its actual height (seems pretty weird that I wonder if its a bug) and stylesheet stuff seems to only affect the drop down list and/or the line edit but not the frame of the qcombobox. Does anyone have any suggestions?? Literally just trying to make the damn thing like 2px bigger vertically!

    Here's what i've got:

    import sys
    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtWidgets import QWidget, QComboBox, QDialog, QApplication
    from PyQt5.QtGui import *
    from PyQt5.QtCore import Qt, QSize

    class combo(QDialog):

    def __init__(self):
    super().__init__()

    containers = ['1','2','3','4','5']
    cbox = QComboBox(self)
    cbox.setFixedSize(80, 30)
    cbox.setStyleSheet('QComboBox {font: 16pt Arial}')
    cbox.setEditable(True)
    cbox.lineEdit().setFixedSize(50, 18)
    cbox.addItems(containers)
    cbox.setSizeAdjustPolicy(1)
    cbox.move(50, 50)

    for i in range(len(containers)):
    cbox.model().setData(cbox.model().index(i,0), QSize(80, 30), Qt.SizeHintRole)

    cbox.show()


    if __name__ == '__main__':
    app = QApplication(sys.argv)

    demo = combo()
    demo.show()

    sys.exit(app.exec_())

    Continue reading...

Compartilhe esta Página