Results 1 to 11 of 11

Thread: QScrollArea Sizing

  1. #1
    Join Date
    Oct 2010
    Posts
    11

    Default QScrollArea Sizing

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QScrollArea Sizing

    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?

  3. #3
    Join Date
    Oct 2010
    Posts
    11

    Default Re: QScrollArea Sizing

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea Sizing

    Quote Originally Posted by LIRiot View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2010
    Posts
    11

    Default Re: QScrollArea Sizing

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea Sizing

    Quote Originally Posted by LIRiot View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2010
    Posts
    11

    Default Re: QScrollArea Sizing

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea Sizing

    Quote Originally Posted by LIRiot View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2010
    Posts
    11

    Default Re: QScrollArea Sizing

    Can you tell me how to retrieve the required margins and borders with QStyle?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea Sizing

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Oct 2010
    Posts
    11

    Default Re: QScrollArea Sizing

    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.

Similar Threads

  1. Replies: 0
    Last Post: 30th April 2010, 05:22
  2. Replies: 2
    Last Post: 10th March 2008, 20:16
  3. QGraphicsSvgItem sizing
    By jefferai in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2007, 21:48
  4. Sizing problem
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 7
    Last Post: 2nd April 2007, 17:31
  5. sizing question
    By jlgerber in forum Newbie
    Replies: 1
    Last Post: 20th November 2006, 16:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.