1 votes

How to center text in PyQt ComboBox?

I have created a table where all its items have been centered, except the ComboBox, I have tried some QtCore methods without success, is there a way?

Note: Item c1 of the mas function is the combo box.

 import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QComboBox, QTableWidgetItem, QMessageBox
from PyQt5.uic import loadUi
from PyQt5.QtCore import Qt
class SubwindowDatosEntrada(QMainWindow):

    def __init__(self, root=None):

    def mas(self):
        nuevo = self.table_datosEntrada.rowCount()
        self.table_datosEntrada.insertRow(nuevo)

        for row in range(self.table_datosEntrada.rowCount() - 1, 
            self.table_datosEntrada.rowCount(), 1):
            for rowe in range(self.table_datosEntrada.columnCount()):

                #Combo Box
                c1 = QComboBox()
                c1.lineEdit().setAlignment(Qt.AlignCenter)
                c1.addItems(['Casa', 'Vivienda'])

                # Números en celdas centradas                 
                item = QTableWidgetItem(str(self.table_datosEntrada.rowCount()))
                itemb = QTableWidgetItem()
                item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
                itemb.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)                

                self.table_datosEntrada.setCellWidget(row, 1, c1)
                self.table_datosEntrada.setCellWidget(row, 12, c2)
                self.table_datosEntrada.setItem(row, 0, item)
                self.table_datosEntrada.setItem(row, rowe, itemb)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = SubwindowDatosEntrada()
    widget.show()
    sys.exit(app.exec_())

Thanks.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X