Question

Here is my code:

#class...
def setupLayout(self):
    self.resize(1000, 600)
    label1 = QtGui.QLabel(u'<font color=green><b><i>Полученные сообщения:</i></b></font>')
    label2 = QtGui.QLabel(u'<font color=green><b><i>Описание сообщений:</i></b></font>')

    self.mainList = QtGui.QListWidget()
    self.descList = QtGui.QListWidget()
   
    grid = QtGui.QGridLayout()
    grid.setSpacing(1)
    
    grid.addWidget(label1, 1, 1)
    grid.addWidget(label2, 1, 2)
  
    grid.addWidget(self.mainList, 2, 1, 5, 1)
    grid.addWidget(self.descList, 2, 2, 5, 1)
#other definitions....

I want to reduce distance between my labels and panel with the title of the window: grid layout problem

So if I use this code, the distance is good, but listBoxes holds only one row:

grid.addWidget(self.mainList, 2, 1, 1, 1)
grid.addWidget(self.descList, 2, 2, 1, 1)

enter image description here

How can I add a small distance?

Was it helpful?

Solution

I tend to use QGridLayout for homogeneous contents. For your purpose a combination of QHBoxLayout and QVBoxLayout would work better.

left = QtGui.QVBoxLayout()
# This makes the label take as little space as possible
# since QLabel's sizeHint is Minimum.
left.addWidget(label1, 0)
left.addWidget(self.mainList, 1)

right = QtGui.QVBoxLayout()
right.addWidget(label2, 0)
right.addWidget(self.descList, 1)

main = QtGui.QHBoxLayout()
main.addLayout(left, 1)    # Both sides take the same amount of space.
main.addLayout(right, 1)

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top