Note that there are some explanatory texts on larger screens.

plurals
  1. POQLabel showing an image inside a QScrollArea
    primarykey
    data
    text
    <p>I've successfully implemented a Image Viewer (for DICOM) in Qt. I can see the image and I can zoom in and out correctly.</p> <p>Now, I want to see scroll bars if the image is too big to show when I zoom in.</p> <p>I've used the UI. I placed a <strong>QScrollArea</strong>. Inside, the <strong>QLabel</strong>. The <em>verticalScrollBarPolicy</em> is <em>ScrollBarAsNeeded</em>. The <em>horizontalScrollBarPolicy</em> is <em>ScrollBarAsNeeded</em>.</p> <p>The problem is: it doesn't work. I zoom in, but no scrollbar appears.</p> <h1>Second try: using a layout inside the QScrollArea.</h1> <p>So now there's a <strong>QWidget</strong> between the QScrollArea and the QLabel: a horizontal layout. Opened the same image, now I can see a vertical scroll bar on the right. The image is streched from left to right. When I zoom the image gets its correct proportion.</p> <p>BUT... I zoom out and the scroll bar is the same, even if I can see the whole image. The horizontal scroll bar never appears.</p> <p>Resizing the QLabel doesn't seem to affect. But if I resize the QScrollArea (resizing the main window) the horizontal scroll bar appears.</p> <h1>I've been checking some numbers:</h1> <h2>In the QScrollArea</h2> <ul> <li>Its size changes: below 599 width (why this number? I can't see it anywhere) the horizontal bar appears.</li> <li><em>sizeHint()</em> always returns the same values: 33x41</li> </ul> <h2>In the QLabel</h2> <ul> <li>The dimensions change, but that doesn't affect.</li> <li><em>sizeHint()</em> always returns the same values: 560x1558</li> </ul> <p>Here is the code in XML from the UI designer:</p> <pre><code>&lt;widget class="QWidget" name="centralWidget"&gt; &lt;property name="autoFillBackground"&gt; &lt;bool&gt;false&lt;/bool&gt; &lt;/property&gt; &lt;layout class="QVBoxLayout" name="verticalLayout"&gt; &lt;property name="margin"&gt; &lt;number&gt;0&lt;/number&gt; &lt;/property&gt; &lt;item&gt; &lt;widget class="QScrollArea" name="scrollArea"&gt; &lt;property name="widgetResizable"&gt; &lt;bool&gt;true&lt;/bool&gt; &lt;/property&gt; &lt;property name="alignment"&gt; &lt;set&gt;Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop&lt;/set&gt; &lt;/property&gt; &lt;widget class="QWidget" name="scrollAreaWidgetContents"&gt; &lt;property name="geometry"&gt; &lt;rect&gt; &lt;x&gt;0&lt;/x&gt; &lt;y&gt;0&lt;/y&gt; &lt;width&gt;637&lt;/width&gt; &lt;height&gt;649&lt;/height&gt; &lt;/rect&gt; &lt;/property&gt; &lt;layout class="QHBoxLayout" name="horizontalLayout_2"&gt; &lt;item&gt; &lt;widget class="QLabel" name="miImagen"&gt; &lt;property name="sizePolicy"&gt; &lt;sizepolicy hsizetype="Preferred" vsizetype="Preferred"&gt; &lt;horstretch&gt;0&lt;/horstretch&gt; &lt;verstretch&gt;0&lt;/verstretch&gt; &lt;/sizepolicy&gt; &lt;/property&gt; &lt;property name="autoFillBackground"&gt; &lt;bool&gt;true&lt;/bool&gt; &lt;/property&gt; &lt;property name="scaledContents"&gt; &lt;bool&gt;true&lt;/bool&gt; &lt;/property&gt; &lt;property name="alignment"&gt; &lt;set&gt;Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop&lt;/set&gt; &lt;/property&gt; &lt;/widget&gt; &lt;/item&gt; &lt;/layout&gt; &lt;/widget&gt; &lt;/widget&gt; &lt;/item&gt; &lt;/layout&gt; &lt;/widget&gt; </code></pre> <p>What am I missing? Thank you.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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