Jump to content

  • Log In with Google      Sign In   
  • Create Account

QT. ScrollArea not showing.


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Dospro   Members   -  Reputation: 222

Like
0Likes
Like

Posted 14 August 2014 - 07:32 PM

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?



#2 BitMaster   Crossbones+   -  Reputation: 8007

Like
0Likes
Like

Posted 15 August 2014 - 12:07 AM

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'.



#3 Dospro   Members   -  Reputation: 222

Like
0Likes
Like

Posted 15 August 2014 - 10:46 AM

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, 15 August 2014 - 12:05 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS