PDA

View Full Version : QScrollArea Sizing



LIRiot
25th October 2010, 23:36
I have a custom QWidget which displays images. This widget is placed into a QScrollArea. When a new image is loaded, I would like for my main window to attempt to enlarge in hopes of not having scroll-bars. However, every way I attempt this, the size is just too small. Is there a correct way to do this?

tbscope
26th October 2010, 06:36
Yes, there's a way. Do not use a QScrollArea. The word "scroll" in QScrollArea should give you a hint that it uses scrollbars when the content is bigger than what can be shown.

Besides that, in my opinion, what you want to do is flawed. What if the image you want to display is bigger than the physical screen?

LIRiot
26th October 2010, 14:28
TBScope:

Maybe I should explain better. Let's say my dialog-size is 320*240 and they load an image that is 640*480. I would like to increase the dialog-size up to a maximum of 800*600. So, if they open a large image, they get scrolls, if they open a medium size image, it will put it in "perfect-view." But, I don't want to just make the dialog bigger, I want it to fit. For example, if they load an image of size 640*480, I don't want to jump straight to 800*600. I want it to fit to that image. Now if they open an image 1024*768 for example, I want it 800*600 with the image being scrollable. These numbers are examples not exact, but it gives you a better idea of my goal. I want scrolls, but sometimes it doesn't make sense to scroll.

wysota
26th October 2010, 16:33
Maybe I should explain better. Let's say my dialog-size is 320*240 and they load an image that is 640*480. I would like to increase the dialog-size up to a maximum of 800*600. So, if they open a large image, they get scrolls, if they open a medium size image, it will put it in "perfect-view."
Let's assume I am a user of your application. I have started the app and I have also started a web browser because I wanted to check out the live results of the latest Formula 1 GP. I reduced the size of the window belonging to your aplication because I wanted to see the complete table of results of all 24 drivers but at the same time I'm working with your application. I open some file in your app and wham! it resizes covering my browser window. So I scale your app down again to see the F1 results. I open some other file in your app and wham! it resizes again. What do I do next? I uninstall your application and find a replacement that won't try to be smarter than its user.

LIRiot
26th October 2010, 17:28
Wysota, you have a point, but that's why we have options. Are you honestly telling me that you can't ever see a reason to scale a scrollable area to size? What about when your image is a part of a multi-document interface? Doesn't it make sense to load a small->medium size image in full-view? And if you just set a static size at which it loads, then you have the problem of it perhaps being JUST too big for the static size. Then you have scroll bars which take up room causing the edges to be cut off when the image is just 1 pixel too large for the static size. Of course it becomes more than 1-pixel once the scroll-bars come into play.

I take it by the responses there is no way to tell the size at which a scrollable area needs to be to fit its contents?

wysota
26th October 2010, 18:16
Wysota, you have a point, but that's why we have options. Are you honestly telling me that you can't ever see a reason to scale a scrollable area to size?
I already had this discussion with someone on this forum. No, I can't ever see such a reason. If I wanted to have such functionality, I would put a button called "adjust window to content" in my application but would never do the adjustment automatically.


What about when your image is a part of a multi-document interface? Doesn't it make sense to load a small->medium size image in full-view?
I would rather maximize the document window when loading a new document. But if I had an existing window and loading a document into that, I would never scale up the window because it might break the user experience.


And if you just set a static size at which it loads, then you have the problem of it perhaps being JUST too big for the static size. Then you have scroll bars which take up room causing the edges to be cut off when the image is just 1 pixel too large for the static size.
The counter argument might be that you want to scale up to 800x600 and the image could have the size of 801x601 and you would still have scroll bars. Or my desktop could be 640x480 in size and I'd have to do weird things just to be able to resize the window (I actually had seen an application do that).


I take it by the responses there is no way to tell the size at which a scrollable area needs to be to fit its contents?
Sure there is. It's the size of the contents plus the size of the margins around the viewport plus the size of the viewport border.

LIRiot
26th October 2010, 20:13
What would the proper method be of getting the sizes of the margins and borders? If I were to create this "adjust-to-size" button? See, I completely understand why you would suggest that it could be a problem that such a thing is automated. But, I feel it is just as wrong not to allow this to be done at all. While you may not prefer your windows of size, some people do, and having to manually adjust the borders for each image ever loaded is a major pain.

wysota
26th October 2010, 20:19
What would the proper method be of getting the sizes of the margins and borders?
Asking the style could be one way to do it.

LIRiot
27th October 2010, 01:14
Can you tell me how to retrieve the required margins and borders with QStyle?

wysota
27th October 2010, 01:28
No, I don't know all the constants by heart. It's best to look into source-code of QAbstractScrollArea to see what gets called by it. It could be that you can get the proper numbers (at least for the padding of the viewport relative to the whole widget) by the public API of the latter.

LIRiot
27th October 2010, 14:37
I will look into this, thank you. Also I think I have come to like the idea of a button. I think I will go with modding the UI to have an action which pops it to full-size or full-screen depending on obviously which makes more sense.