# What is QMatirx::inverted is being used in QGraphicsView

• what is matrix inverted http://doc.qt.io/qt-4.8/qmatrix.html#inverted

I went through documentation on http://doc.qt.io/qt-4.8/qmatrix.html#inverted and what is matrix inverted

• @Qt-Enthusiast

Matrix inversion is a defined, mathematical operation on numerical matrices comparable to simple division of numbers.

• Ok Why is it is used in QgraphicsView . is it because

/ 0,0 is top/left corner in qt - flip vertically to make it bottom/left

• is some one expert why matrix inversion is used in QgraphicsView

• @Qt-Enthusiast Which exact use of matrix inversion in QGraphicsView do you mean?

• @jsulm Likely this one

• I can share the code if you want

• void myView::mouseReleaseEvent() {
createCoreBox();
}
void myView::createCoreBox(QRect rect)
{
// convert rect to db coordinates
QRect p = d_matrix.inverted().mapRect(mapToScene(rect).boundingRect().toRect());

}

I am not able to get why inverted matrix is used in above code

• A matrix is a (discrete) linear operator that maps one vector space into another; the inverse of a matrix, if it exists, which it may not, reverses the mapping.

In layman terms, a matrix is simply a transformation that preserves distance. The inverse of the matrix is the inverse transformation. Scaling, shearing, rotating, translating, axis inversion(s) are all transformations that can be represented by one or more matrices.

... as for your other thread mentioned by @SGaist, no matrix inversion will do you no good to invert the axes, nor will it be helpful in moving the coordinate point origin. You need to construct the appropriate transformation matrix to achieve that, which is rather simple:

``````1    0   0
0   -1  -H
0    0   1
``````

where `H` is the height of the widget/scene/whatever and is used to shift the coordinate system's origin so it coincides with the bottom left corner. Read more on matrices and transformations here.

• void myView::createCoreBox(QRect rect)
{
// convert rect to db coordinates
QRect p = d_matrix.inverted().mapRect(mapToScene(rect).boundingRect().toRect());

}

My QRect co ordinates are

Rect 123 202 333 42

but mapTpScenece(Rect) returns Rect 0 -1 -1 0 <. I am not sure why in which case mapToScence returns 0 -1 -1 0

• I am not sure why in which case mapToScence returns 0 -1 -1 0

You have plenty of information in this thread, so you need to read up on the math and understand it; only then start to write down code. The "throw it against the wall and see what sticks" method will bring you only so far ...