I'm new to PyQt5 and running into an issue with resizing the main window after certain widget changes. I'm developing a PyQt5 application where I have a home page and a tasks page. I want my home page to have a geometry of (200, 200) and the tasks page to be (1200, 1200). Here's a snippet of my code:
In my `main.py` file, I have set up a `QStackedWidget` where I load `MainWindow` and `Tasks`. In `task_func`, I want to switch widgets, but I'm not sure how to adjust the resizing correctly. Does anyone have experience with this? Do I need to use different layouts for each widget?
2 Answers
It sounds like you're trying to dynamically resize your window based on what widget is displayed. Instead of setting fixed sizes, it's better to put your widgets into layouts. This allows for automatic resizing as the window layout changes. For example, you could use a QVBoxLayout or QGridLayout instead of absolute positioning. It also gives you more control over how these widgets scale. If you really need fixed sizes, just set them in your widget's `resize()` method after you switch the current index.
That's a good question! When working with PyQt5, you generally want to avoid fixed sizes. Instead, create layouts for each widget that dictate how they should scale. This way, when you switch between your home page and your tasks page, the window should resize automatically without needing to manually set sizes each time. You might need to call `adjustSize()` on your main window after changing the widget.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically