Closed philipp-radio closed 4 months ago
I doubt this is a pytest-qt issue. Can you call Qt's gui.main_window.grab()
manually and see if that shows the same behavior?
Yes you're right it's the same behavior. Can you make a guess why it's behaving this way?
Closing this issue as it is not a pytest-qt problem. Thanks for your help :)
The implementation of QWidget::grab()
starts with:
QPixmap QWidget::grab(const QRect &rectangle)
{
Q_D(QWidget);
if (testAttribute(Qt::WA_PendingResizeEvent) || !testAttribute(Qt::WA_WState_Created))
sendResizeEvents(this);
with that being defined as:
Indicates that a resize event is pending, e.g., when a hidden widget was resized. This flag is set or cleared by the Qt kernel.
So you might just need to actually show your widget?
I created a test using
pytest-qt
for a customQMdiArea
implementation. When doing this I noticed that taking a screenshot changes the program behavior. Code to replicate looks something like this:I noticed that the values stay the same (and are wrong), even though I resized the main window. If I now take screenshots before & after resizing however, the values are correct:
I'm running the tests with
tox
and setting theQT_QPA_PLATFORM
variable tooffscreen
and I guess the problem has something to do with that? I'm doing it this way because I got the tests working in a Gitlab CI pipeline with this configuration.Just for reference, my implementation of QMdiArea looks like the following:
I'm using PyQt 5.15.10 and pytest-qt 4.4.0.