I have a two-pane horizontal QSplitter that takes up the entire window. The right pane is irrelevant for now. I've given it a dummy QFrame. The left pane contains a QScrollArea with a custom widget inside of it. I want to give this widget a minimum width and height so that scrollbars will come into play whenever the QSplitter pane is too small. However I also want the custom widget to expand to fill any excess space if the QSplitter pane is larger than the minimum dimensions of the widget.

How do I make it dynamically expand? I've tried simply using CSS on the QScrollArea to give it the same background color as the widget, but that changes the color of the scrollbars too.

Qt Code:
  1. import sys
  2. from PyQt5.QtCore import *
  3. from PyQt5.QtWidgets import *
  4. from PyQt5.QtGui import *
  5.  
  6.  
  7. class MyWidget(QWidget):
  8.  
  9. def __init__(self, parent = None):
  10.  
  11. QWidget.__init__(self, parent)
  12. self.color = QColor(255, 255, 255)
  13.  
  14.  
  15. def paintEvent(self, event):
  16.  
  17. painter = QPainter()
  18. painter.begin(self)
  19. painter.fillRect(event.rect(), QBrush(self.color))
  20. painter.end()
  21.  
  22.  
  23. def sizeHint(self):
  24.  
  25. return QSize(250, 600)
  26.  
  27.  
  28. if __name__ == "__main__":
  29.  
  30. app = QApplication(sys.argv)
  31. window = QWidget()
  32.  
  33. right = QFrame()
  34. right.setFrameShape(QFrame.StyledPanel)
  35.  
  36. mywidget = MyWidget()
  37.  
  38. splitter = QSplitter(Qt.Horizontal)
  39.  
  40. scroll = QScrollArea()
  41. scroll.setWidget(mywidget)
  42.  
  43. splitter.addWidget(scroll)
  44. splitter.addWidget(right)
  45.  
  46. layout = QHBoxLayout()
  47. layout.addWidget(splitter)
  48.  
  49. window.setLayout(layout)
  50.  
  51. window.show()
  52. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode