Qt: Avoid using casting to wrong type of event

This commit is contained in:
TellowKrinkle
2026-10-07 21:11:51 -05:00
parent 58967fdc42
commit 270560f8e6
+13 -5
View File
@@ -467,21 +467,29 @@ bool RenderWidget::event(QEvent* event)
SetCursorLocked(m_cursor_locked);
break;
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
case QEvent::DevicePixelRatioChange:
#else
// According to https://bugreports.qt.io/browse/QTBUG-95925 the recommended practice for
// handling DPI change is responding to paint events
case QEvent::Paint:
#endif
case QEvent::Resize:
{
SetCursorLocked(m_cursor_locked);
const QResizeEvent* se = static_cast<QResizeEvent*>(event);
QSize new_size = se->size();
QScreen* screen = window()->windowHandle()->screen();
const float dpr = screen->devicePixelRatio();
const int width = new_size.width() * dpr;
const int height = new_size.height() * dpr;
int width = m_last_window_width;
int height = m_last_window_height;
if (event->type() == QEvent::Resize)
{
QSize new_size = static_cast<QResizeEvent*>(event)->size();
width = new_size.width();
height = new_size.height();
}
if (m_last_window_width != width || m_last_window_height != height ||
m_last_window_scale != dpr)