Drawing a static grid on a pixmap/Qlabel
Unsolved
General and Desktop
-
I have an app that displays an image in a QLabel. I zoom and drag the image with the mouse - this works! (yea for me)
What I want to do now is to draw a (Rule of Thirds) grid over the image.
The problem is that the grid moves whenever I drag the image.
I've tried using coordinates bases on width() and height() of the ImageLabel and of the pixmap returned via pixmap();
Neither results in a static grid.
HELP!!!
-
For the historical record, I finally got it working. My code:
`
QRect screenGeometry = QGuiApplication::primaryScreen( )->geometry( ); int x13; int x23; int y13; int y23; if( screenGeometry.width( ) < width( )) { x13 = m_image->getScrollX( ) + screenGeometry.width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * screenGeometry.width( ) / 3.0; } else { x13 = m_image->getScrollX( ) + width( ) / 3.0; x23 = m_image->getScrollX( ) + 2 * width( ) / 3.0; } if( screenGeometry.height( ) < height( )) { y13 = m_image->getScrollY( ) + screenGeometry.height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * screenGeometry.height( ) / 3.0; } else { y13 = m_image->getScrollY( ) + height( ) / 3.0; y23 = m_image->getScrollY( ) + 2 * height( ) / 3.0; } QPainter painter( this ); painter.setPen( QPen( Qt::red, 4, Qt::SolidLine, Qt::FlatCap )); painter.drawLine( 0, y13, width( ), y13 ); painter.drawLine( 0, y23, width( ), y23 ); painter.drawLine( x13, 0, x13, height( )); painter.drawLine( x23, 0, x23, height( ));
}
`