Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried following <a href="http://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html" rel="nofollow">Qt's scroll area example</a>? If you're using a QLabel to display your image, then the use of QScrollArea is pretty much the standard way of achieving what you want. You use it like so (from the example):</p> <pre><code> imageLabel = new QLabel; imageLabel-&gt;setBackgroundRole(QPalette::Base); imageLabel-&gt;setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); imageLabel-&gt;setScaledContents(true); scrollArea = new QScrollArea; scrollArea-&gt;setBackgroundRole(QPalette::Dark); scrollArea-&gt;setWidget(imageLabel); setCentralWidget(scrollArea); </code></pre> <p>Then zooming is handled like so:</p> <pre><code> void ImageViewer::zoomIn() { scaleImage(1.25); } void ImageViewer::zoomOut() { scaleImage(0.8); } void ImageViewer::scaleImage(double factor) { Q_ASSERT(imageLabel-&gt;pixmap()); scaleFactor *= factor; imageLabel-&gt;resize(scaleFactor * imageLabel-&gt;pixmap()-&gt;size()); adjustScrollBar(scrollArea-&gt;horizontalScrollBar(), factor); adjustScrollBar(scrollArea-&gt;verticalScrollBar(), factor); zoomInAct-&gt;setEnabled(scaleFactor &lt; 3.0); zoomOutAct-&gt;setEnabled(scaleFactor &gt; 0.333); } void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor) { scrollBar-&gt;setValue(int(factor * scrollBar-&gt;value() + ((factor - 1) * scrollBar-&gt;pageStep()/2))); } </code></pre> <p>You can, of course, get a better idea of what's going on by looking at the example, but that's the gist of it. I think perhaps the adjustScrollBar() function might be the most helpful thing for you.</p> <p>Your last comment on the original post is correct, the QScrollArea doesn't magically notice the change in size of its contents. Look at how the example uses adjustScrollBar() to compensate for this fact.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload