Manipulation and grid, hbox and vbox in pyqt4

1

I'm a beginner and I'm making a graphical interface with the help of pyqt4. I need to add two columns of buttons where there is only one, but every time I try, the button goes to the right and spoils the proportions. Can anyone help me? What I have so far is this:

self.main_frame = qg.QWidget()
self.area_canvas()
self.create_toolbox() 
self.botao_enviar = qg.QPushButton('ENVIAR')
self.botao_salvarr = qg.QPushButton('SALVAR')
self.botao_restaurar = qg.QPushButton("RESTAURAR")
self.botao_criar = qg.QPushButton(_tr("CRIAR"))
grid = qg.QGridLayout()
grid.addWidget(self.canvas,0,0,5,4)
grid.addWidget(self.botao_enviarr,0,4) 
grid.addWidget(self.botao_salvar,1,4)
grid.addWidget(self.botao_restaurar,2,4) 
grid.addWidget(self.botao_criar,3,4)
grid.addWidget(self.toolBox,4,4)
grid.addWidget(self.chk_id_pontos,6,0)
grid.addWidget(self.chk_id_barras,6,1)

self.main_frame.setLayout(grid)
self.setCentralWidget(self.main_frame)
    
asked by anonymous 21.10.2018 / 04:21

1 answer

1

Here is a very simple example of how to use two columns with QGridLayout:

self.botao_enviar = qg.QPushButton('ENVIAR')
self.botao_salvar = qg.QPushButton('SALVAR')
self.botao_restaurar = qg.QPushButton('RESTAURAR')
self.botao_criar = qg.QPushButton('CRIAR')
self.botao_enviar2 = qg.QPushButton('ENVIAR2')
self.botao_salvar2 = qg.QPushButton('SALVAR2')
self.botao_restaurar2 = qg.QPushButton('RESTAURAR2')
self.botao_criar2 = qg.QPushButton('CRIAR2')

grid = qg.QGridLayout()
grid.addWidget(self.canvas,0,0,5,1)
grid.addWidget(self.botao_enviar,0,1) 
grid.addWidget(self.botao_salvar,1,1)
grid.addWidget(self.botao_restaurar,2,1) 
grid.addWidget(self.botao_criar,3,1)
grid.addWidget(self.botao_enviar2,0,2) 
grid.addWidget(self.botao_salvar2,1,2)
grid.addWidget(self.botao_restaurar2,2,2) 
grid.addWidget(self.botao_criar2,3,2)

Note that here I modified for canvas to occupy only one column:

grid.addWidget(self.canvas,0,0,5,1)

If the problem is controlling the proportion of each part, you can do this:

grid.setColumnStretch(0,3) # coluna zero (a do canvas) vai ter proporção 3
grid.setColumnStretch(1,1) # coluna um (primeira fileira) vai ter proporção 1
grid.setColumnStretch(2,1) # coluna dois (segunda fileira) vai ter proporção 1

Result:

RememberthatinthesecasesitmaybemoreconvenienttouseanHBox,inthisHBoxcanbyonecanvasandtwoVBox.ThenineachVBoxyouputthedesiredbuttons.

Documentation:

21.10.2018 / 05:23