0

I'm having some problems with the Central Widget, I'm trying to positionate the LabelTitle overlapping the top of the central widget, so it would look like a small box title, but for some reason I can't figure out how to stretch the space between the layout and the top of the central widget.

I tried using a Frame, or the layout.setRowStretch but it didn't work for me

class WindowEtiquette(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setFixedSize(460, 350)
        
        self._add_widgets()
        
    def _add_widgets(self):
        self.CuadroLayout = QGridLayout()
        
        #Generando elementos y layouts
        
        self.TituloLayout = QGridLayout()
        self.labelTitulo = QLabel("Formato de la dirección")
        self.labelTitulo.setObjectName("EtiquetaTitulo")
        self.TituloLayout.addWidget(self.labelTitulo, 0, 0, Qt.AlignCenter)
        
       
        self.CuadroLayout.addLayout(self.TituloLayout, 0, 0, alignment=Qt.AlignTop)   

        self.widgetCentral = QWidget()
        self.widgetCentral.setObjectName("FondoEtiqueta")
        self.widgetCentral
        
        self.widgetCentral.setLayout(self.CuadroLayout)
        self.setCentralWidget(self.widgetCentral)      

The objects name are in a CSS File, and I don't add any margins or paddings in them

enter image description here

I know maybe I shouldn't worry too much about the GUI, but I wanted to see if I could solve that problem

musicamante
  • 41,230
  • 6
  • 33
  • 58
  • Your code doesn't match the screenshot, please [edit] your post with the current code, so that we can understand what's wrong with it. Be careful with the [formatting](https://meta.stackoverflow.com/a/251362) (check the post preview before submitting). – musicamante Jan 27 '22 at 19:51

1 Answers1

0

I'm sorry, I am kind of new in this place so I guess I jumped over conclusions, I'm sorry if the code it's too big, I was in kind of a rush doing it so I just did a mess, but here it is:

class VentanaEtiqueta(QMainWindow):
    def __init__(self):
        #Valores iniciales de la ventana
        super().__init__()
        self.setFixedSize(460, 340)
        
        #Función de generar elementos
        self._agregar_Componentes()
        
    def _agregar_Componentes(self):
        self.datos = cargarDatos(ARCH_CLIENTES) #Archivo de clientes
        
        #Generando layout padre
        self.CuadroLayout = QGridLayout()
        
        #Generando elementos y layouts
        
        self.TituloLayout = QGridLayout()
        self.labelTitulo = QLabel("Formato de la dirección")
        self.labelTitulo.setObjectName("EtiquetaTitulo")
        self.TituloLayout.addWidget(self.labelTitulo, 0, 0)
        
        
        self.NombreSeccion = QGridLayout()
        self.NombreLabel = QLabel("Nombre: ")
        self.NombreComboBox = QComboBox()
        self.NombreLabel.setObjectName("Secciones"), self.NombreComboBox.setObjectName("Seleccionador")
        self.NombreComboBox.setEditable(True)
        self.NombreComboBox.setPlaceholderText("Céd-NombreCompleto")
        
        #Creando un autocompletador para el QComboBox
        self.completador = QCompleter(obtenerCedula_Nombres(self.datos), self) 
        self.completador.setCaseSensitivity(Qt.CaseSensitive)
        self.NombreComboBox.setCompleter(self.completador)
        
        self.NombreSeccion.setContentsMargins(10, 5, 20, 15)
        self.NombreSeccion.setSpacing(20)
        self.NombreSeccion.addWidget(self.NombreLabel, 0, 0, Qt.AlignLeft)
        self.NombreSeccion.addWidget(self.NombreComboBox, 0, 1)
        
        self.NombreComboBox.currentTextChanged.connect(self._autoCompletarINFO)
        
        
        self.DireccionE_Seccion = QGridLayout()
        self.dirEspefLabel, self.dirEspefLineEdit = QLabel("Dirección específica: "), QLineEdit()
        self.dirEspefLabel.setObjectName("Secciones"), self.dirEspefLineEdit.setObjectName("Editor")
        self.dirEspefLineEdit.setDisabled(True)
        self.DireccionE_Seccion.setContentsMargins(10, 0, 20, 15)
        self.DireccionE_Seccion.setSpacing(20)
        self.DireccionE_Seccion.addWidget(self.dirEspefLabel, 0, 0, Qt.AlignLeft)
        self.DireccionE_Seccion.addWidget(self.dirEspefLineEdit, 0, 1)
        
        self.DireccionG_Seccion = QGridLayout()
        self.dirGenLabel, self.dirGenLineEdit = QLabel("Dirección general: "), QLineEdit()
        self.dirGenLabel.setObjectName("Secciones"), self.dirGenLineEdit.setObjectName("Editor")
        self.dirGenLineEdit.setDisabled(True)
        self.DireccionG_Seccion.setContentsMargins(10, 0, 20, 15)
        self.DireccionG_Seccion.setSpacing(20)
        self.DireccionG_Seccion.addWidget(self.dirGenLabel, 0, 0, Qt.AlignLeft)
        self.DireccionG_Seccion.addWidget(self.dirGenLineEdit, 0, 1)

        self.CodigoSeccion = QGridLayout()
        self.CodLabel, self.CodLineEdit = QLabel("Codigo: "), QLineEdit()
        self.CodLabel.setObjectName("Secciones"), self.CodLineEdit.setObjectName("Editor")
        self.CodLineEdit.setDisabled(True)
        self.CodigoSeccion.setContentsMargins(10, 0, 20, 0)
        self.CodigoSeccion.setSpacing(20)
        
        self.CodigoSeccion.addWidget(self.CodLabel, 0, 0, Qt.AlignLeft)
        self.CodigoSeccion.addWidget(self.CodLineEdit, 0, 1)
        
        self.PaisSeccion = QGridLayout()
        self.paisLabel = QLabel("Costa Rica")
        self.paisLabel.setObjectName("Secciones")
        self.PaisSeccion.setSpacing(20)
        self.PaisSeccion.setContentsMargins(10, 0, 20, 5)
        self.PaisSeccion.addWidget(self.paisLabel, 0, 0, Qt.AlignLeft)
        
        self.Boton = QPushButton("Generar PDF")
        self.Boton.setObjectName("GenerarPDF")

        self.CuadroLayout.addLayout(self.TituloLayout, 0, 0, alignment=Qt.AlignTop)   
        self.CuadroLayout.addLayout(self.NombreSeccion, 1, 0)
        self.CuadroLayout.addLayout(self.DireccionE_Seccion, 2, 0)
        self.CuadroLayout.addLayout(self.DireccionG_Seccion, 3, 0)
        self.CuadroLayout.addLayout(self.CodigoSeccion, 4, 0)
        self.CuadroLayout.addLayout(self.PaisSeccion, 5, 0)
        self.CuadroLayout.addWidget(self.Boton, 6, 0, Qt.AlignCenter)

I