Manipulation and grid, hbox and Vbox in pyqt4

Asked

Viewed 14 times

0

I’m a beginner and I’m doing a graphical interface with the help of pyqt4. I need to add two columns of buttons there where there’s only one, but every time I try, the button goes to the right and ruins the proportions.ali 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)

1 answer

1


Here is a 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 to the canvas 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 so:

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

Upshot:

screenshot com duas fileiras verticais de botões

Remember that in these cases it may be more convenient to use an Hbox, in this Hbox can by a canvas and two Vbox. There in each Vbox you put the desired buttons.

Documentation:

  • It served perfectly! Thank you very much!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.