• Advertisement
Sign in to follow this  

QT. ScrollArea not showing.

This topic is 1255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi again.

 

In the QT application i'm developing i have the following problem.

 

In the main window i have some layouts and a splitter with widget that work perfectly.

 

Now, one of those widgets is a custom widget.

What i need is to put some scrollbars to this Widget. This widget holds a Qimage which is painted with a QPainter object within the widget using the paintevent. Sometimes this image is huge, so that's why i want the scrollbars, to scroll this image.

 

What i did. Was to create a QScrollArea in the mainWindow.

Then i used setWidget to set the customWidget "inside" the scrollArea.

Then i put the scrollArea inside the layout where the widget used to be:

viewer = new cSpriteViewer();
viewerScroller = new QScrollArea;
viewerScroller->setWidget(viewer);
viewerScroller->setWidgetResizable(true);
viewerScroller->setBackgroundRole(QPalette::Dark);
.
.
mainSplitter->addWidget(viewerScroller);
setCentralWidget(mainSplitter);

But it's not working. There are no scrollbars, and i have to resize the window to see the entire image (except when the image is bigger than my desktop resolution).

 

Any ideas?

Share this post


Link to post
Share on other sites
Advertisement

It's been a while since I dealt with QScrollArea, but the first question that pops into my mind is: does cSpriteViewer ensure it has the correct size set? Does is have a preferredSize set?

 

Also as a side note: the framework is called 'Qt', not 'QT'.

Share this post


Link to post
Share on other sites

Thanks for the answer.

 

preferredSize??. Any "good" guide about how to set widget sizes?

 

As a matter of fact, i don't set any "correct" size.

 

From now on i'm writing Qt. Sorry.

 

EDIT:

 

Solved.

What i did was the following.

 

I reimplemented the sizeHint method in my custom Widget class.

When there is no image loaded i the the return a size of 300x300.

When there is an image loaded, it returns the image size as the widget size hint.

That combined with setSizePolicy to Minimum makes it work perfectly.

 

Now, when there is no image, there are no scrollbars. When i load the image, the scrollbars appear and i can scroll the entire image, just the way i wanted.

 

Thanks.

Edited by Dospro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement