ScrollArea custom widget crushed!

I have qscrollarea and inside this qgridlayout. In the grid layout, I create several custom widgets (for simplicity, these widgets are just a group box and a shortcut) and add them to each row.

Instead of displaying a vertical scrollbar, custom widgets are compressed to fit the size of the scroll.

I add custom widgets to the scroll pane in the following way:

    def addBookWidget(self):
    self.book_grid = QtGui.QGridLayout(self.book_scrollArea)

    widget = py_BookWidget(self.book_scrollArea)
    widget2 = py_BookWidget(self.book_scrollArea)
    widget3 = py_BookWidget(self.book_scrollArea)
    widget4 = py_BookWidget(self.book_scrollArea)
    widget5 = py_BookWidget(self.book_scrollArea)
    widget6 = py_BookWidget(self.book_scrollArea)
    widget7 = py_BookWidget(self.book_scrollArea)


    self.book_grid.addWidget(widget,0,0)
    self.book_grid.addWidget(widget2,1,0)
    self.book_grid.addWidget(widget3,2,0)
    self.book_grid.addWidget(widget4,3,0)
    self.book_grid.addWidget(widget5,4,0)
    self.book_grid.addWidget(widget6,5,0)
    self.book_grid.addWidget(widget7,6,0)
    self.book_scrollArea.setLayout(self.book_grid)

    widget.show()
    widget2.show()
    widget3.show()
    widget4.show()
    widget5.show()
    widget6.show()
    widget7.show()

A custom widget extends QWidget and updates sizeHint:

class py_BookWidget(QtGui.QWidget):
def __init__(self, parent=None):
    super(py_BookWidget, self).__init__(parent)
    self.book = Ui_book_widget()  
    self.book.setupUi(self)  #This is loading my QT Designer Code

def sizeHint(self):
    print "test"
    return QtCore.QSize(660, 300)

The sizeHint method is called, but the widgets are still popping out to a much lower height. All elements of the custom widget have a fixed width and height, and the minimum and maximum height and width are 660, 300.

Anyone have a suggestion to try? Thank!

: MainWindow, widgetResizable boolean False.

, scrollArea .

+3
1

QScrollArea . .

QWidget, QScrollArea setWidget()

+1

Source: https://habr.com/ru/post/1795674/


All Articles