Results 1 to 12 of 12

Thread: sizeHint()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sizeHint()

    Great!
    I was able to implement sizeHint like you suggested without the compiler complaining about it (for the first time). If I want to resize the main window, do I just do this?

    Qt Code:
    1. adjustSize();
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QSize sizeHint();
    2. adjustSize();
    To copy to clipboard, switch view to plain text mode 

    Both of these only work abot half the time.
    My question is how does another function that uses sizeHint() actually know to invoke the sizeHint() function? How do you call sizeHint() when you want to use it for adjustSize()?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: sizeHint()

    Quote Originally Posted by sm View Post
    Qt Code:
    1. QSize sizeHint();
    2. adjustSize();
    To copy to clipboard, switch view to plain text mode 
    The first one is not a valid C++ statement. It shouldn't even compile.

    From QWidget::adjustSize() docs:
    Adjusts the size of the widget to fit the contents.

    Uses sizeHint() if valid (i.e if the size hint's width and height are >= 0); otherwise sets the size to the children rectangle that covers all child widgets (the union of all child widget rectangles). For top-level widgets, the screen size is also taken into account.
    As it says, adjustSize() will use the value returned by sizeHint().

    Edit: PS. Oh, actually it is a valid C++ statement. It just constructs a variable of type QSize called sizeHint. However, it won't call that function.
    Last edited by jpn; 21st January 2008 at 19:11. Reason: updated contents
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    sm (21st January 2008)

  4. #3
    Join Date
    Jan 2008
    Posts
    7
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sizeHint()

    For some reason both of the versions compiled. I am now only using the version that you suggested (the second version). But even this only works but only half the time. I understand that sizeHint() + adjustSize() are only executed when they are possible (the size is meaningful) but in my case they don't work when it should be very easy to do what's asked. I know it's very difficult for anyone to trouble-shoot my code without seeing it. So I have to figure it out myself. In order to do this I'd like to know the following:
    a) do you have to put the adjustSize() in in the end of the drawing functions (only execute it after everything else has been done)?
    b) is it OK to put adjustSize() in any function (other than main function)
    c) how do the addStretch commands in they layout constructor affect adjustSize? is it possible that addStretch functions make adjustSize somewhat nonfunctional because they tend to expand the layout (while I try to use adjustSize to contract it).
    Last edited by sm; 21st January 2008 at 21:13.

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

    Default Re: sizeHint()

    "QSize sizeHint();" probably compiles as a "declaration of a local function sizeHint() returning QSize".

  6. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: sizeHint()

    It would be nice if you could post some code.
    BTW sizeHint is used by layouts mainly and if you are using layout then it is enough to just reimplement sizeHint() as suggested. The rest is taken care by the layout.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. sizeHint
    By eric in forum Newbie
    Replies: 1
    Last Post: 8th January 2008, 16:18
  2. How to set the sizehint for treeWidget
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2007, 11:35
  3. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 08:25
  4. invalid sizeHint()
    By roleroz in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2006, 22:11

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
  •  
Qt is a trademark of The Qt Company.