I have a grid area in a scroll area within a dialog
class IndicSelectWindow(QDialog):
def __init__(self, path, parent=None):
super(IndicSelectWindow, self).__init__(parent)
self.resize(500, 400)
self.scroll_area = QScrollArea(self)
self.scroll_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.grid_layout = QGridLayout(self.scroll_area)
self.exec_()
How can I make the grid cover the full area of the scroll_area. it does not have a method setSizePolicy. How can I make this work?
You must add the QGridLayout to the QWidget that is added to the QScrollArea
import sys
from PyQt5 import QtWidgets
class IndicSelectWindow(QtWidgets.QDialog):
def __init__(self, parent=None):
super(IndicSelectWindow, self).__init__(parent=parent)
self.resize(500, 400)
self.layout = QtWidgets.QHBoxLayout(self)
self.scrollArea = QtWidgets.QScrollArea(self)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.gridLayout = QtWidgets.QGridLayout(self.scrollAreaWidgetContents)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.layout.addWidget(self.scrollArea)
for i in range(100):
for j in range(100):
self.gridLayout.addWidget(QtWidgets.QPushButton(), i, j)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = IndicSelectWindow()
w.show()
sys.exit(app.exec_())