QGraphicsview的比例復原

2021-09-29 19:51:19 字數 635 閱讀 1723

我們都知道qgraphicsview的縮放是使用scale函式來設定的,但是每次設定scale都會在之前的基礎上進行縮放,有時間會需要復原原來的縮放比例,就牽扯到qgraphicsview的復原,查詢資料,在網上找到乙個解決方案,貼在下面,望大家可以學習。 

先了解qmatrix,qmatrix包含有6個引數,具體可以檢視文件,簡單來說

m11 - 水平縮放

m12 - 垂直拉伸

m21 - 水平拉伸

m22 - 垂直縮放

dx  - 水平位移

dy - 垂直位移

可以通過qgraphicsview::setmatrix函式來設定比例復原,主要是修改qmatrix的m11和m22來調整。

復原setmatrix

pview->settransformationanchor(qgraphicsview::anchorviewcenter);

qmatrix matrix;

matrix.setmatrix(1, pview->matrix().m12(), pview->matrix().m21(), 1, pview->matrix().dx(), pview->matrix().dy());

pview->setmatrix(matrix, false);

QGraphicsView 擴充套件

過程 1.建立qgraphicsview的子類qthimageview,來實現上述功能 2.介面中新增qgraphicsview控制項,右鍵選擇 提公升為 將其提公升為qthimageview。滑鼠移動事件 滑鼠移動事件在預設情況下,在滑鼠按下的同事拖拽滑鼠時被觸發。qwidget的mousetra...

QGraphicsView相關整理

1 繼承qgraphicsview,改寫下面的protected成員函式進行自定義操作 protected void keypressevent qkeyevent event void mousepressevent qmouseevent event void paintevent qpaint...

純粹透明背景的QGraphicsView

使用qt的qgraphicsview進行動態介面的繪製,通明效果,總是遲早會遇到的,使用setwindowopacity麼?那樣只能讓你的qgraphicsview機器子視窗全部變成通明的,這不是我們說的主題。正常的qwidget,只要設定好父視窗,屬性設定為framelesswindowhint,...