QT中 mdisubwindow中让图片跟随窗口变化

一开始浏览了很多资料,最后还是发现liyuanbhu大神的比较有效,借用他的类

稍微改造下,可去他的博客借用他的类,仅在他的类中加了小段:



case AUTO_SAME:
window_width = width();
window_height = height();
image_width = m_pixmap.width();
image_height = m_pixmap.height();
r1 = window_width / image_width;
r2 = window_height / image_height;
r = qMin(r1, r2);
offset_x = (window_width - r1 * image_width) / 2;
offset_y = (window_height - r2 * image_height) / 2;
painter.translate(offset_x, offset_y);
painter.scale(r1, r2);

painter.drawPixmap(0, 0, m_pixmap);
break
;


直接看效果

QT中 mdisubwindow中让图片跟随窗口变化

QT中 mdisubwindow中让图片跟随窗口变化


QT中 mdisubwindow中让图片跟随窗口变化