logplus/logPlus/MyGraphicsView.cpp
2026-06-12 11:57:17 +08:00

37 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// MyGraphicsView.cpp
#include "MyGraphicsView.h"
MyGraphicsView::MyGraphicsView(QGraphicsScene *scene, QWidget *parent)
: QGraphicsView(scene, parent)
{
// 在构造函数中,可以设置一些视图属性,比如视口更新模式
// setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// 让view的背景透明可选以便与窗口背景融合
this->setStyleSheet("background: transparent;");
this->setFrameShape(QFrame::NoFrame);
this->setContentsMargins(0, 0, 0, 0);
}
void MyGraphicsView::setGraphicsProxyWidget(QGraphicsProxyWidget* proxy)
{
m_proxy = proxy;
}
void MyGraphicsView::resizeEvent(QResizeEvent *event)
{
// 1. 首先调用父类的 resizeEvent这是必须的[reference:4]
QGraphicsView::resizeEvent(event);
// 2. 确保场景存在,然后进行适配
// if (scene()) {
// // 获取场景中所有 items 的边界矩形
// QRectF itemsRect = scene()->itemsBoundingRect();
// if (!itemsRect.isNull()) {
// // 将视图适配到 items 的边界矩形,并保持宽高比
// fitInView(itemsRect, Qt::KeepAspectRatio);
// }
// }
}