Results 1 to 18 of 18

Thread: Resize widget force layout resizing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Resize widget force layout resizing

    Hi,

    I have a Dialog that contain one Widget and the tipical OK_Cancel buttons. The widgets are in a vertical layout.

    I want the dialog to be resized automatically when I resize the Widget . The Widget have to display an image and I want to resize it to a proportional size forcing the dialog to resize.

    Is it posible or have I to change the dialog size manually?

    The widget is a special one similar to OpenGL widget.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    I think it micht happen when you set the minimumSize of your widget. They layout will try to accomodate it and probably resize the dialog. Try and see and let me know.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    implement the resizeEvent function and do all relevant changes there, it shouldn't be difficult

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    Hi,

    Setting the minimum size of the widget don't work.

    Reimplementing the sizeEvent it's not easy as you said, I think. How can I know all the widgets sizes including layout sizes?
    Is there another way to do it? Or if I have to reimplement resizeEvent, how can I get all sizes?

    Thanks,
    Òscar Llarch i Galán

  5. #5
    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: Resize widget force layout resizing

    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    Hi,

    Thanks JPN. I think that this is what I need.

    Good job on this extension library.
    Òscar Llarch i Galán

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    Hi,

    Not exactly waht I need. As I read from docs, "QxtLetterBoxWidget preserves the aspect ratio of its content widget". What I need is to resize the widget and also force the dialog to adjust the size to show the widgets on its new size.

    Really can QxtLetterBoxWidget helps me to this job?

    Thanks,
    Òscar Llarch i Galán

  8. #8
    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: Resize widget force layout resizing

    Quote Originally Posted by ^NyAw^ View Post
    What I need is to resize the widget and also force the dialog to adjust the size to show the widgets on its new size.
    You can make the dialog non-resizable:
    Qt Code:
    1. dialog->layout()->setSizeConstraint(QLayout::SetFixedSize);
    To copy to clipboard, switch view to plain text mode 
    and it will follow the size hint of the content. You just need to implement sizeHint() for your content widget and call updateGeometry() whenever the size hint changes.

    Really can QxtLetterBoxWidget helps me to this job?
    Well, why do you care about the dialog size when the aspect ratio of the content is correct?
    J-P Nurmi

  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    Hi,

    Quote Originally Posted by jpn View Post
    and it will follow the size hint of the content. You just need to implement sizeHint() for your content widget and call updateGeometry() whenever the size hint changes.
    The widget not will resize itself. On myDialog constructor I need to change the size of myWidget:
    Qt Code:
    1. myDialog::myDialog(...)
    2. {
    3. ...
    4. int iWidth = obj->getWidth();
    5. int iHeight = obj->getHeight();
    6. float dAspRat = (float)iWidth/(float)iHeight;
    7.  
    8. int iWidthWidget, iHeightWidget;
    9. iWidthWidget = 640;
    10. iHeightWidget = (640/dAspRat );
    11.  
    12. m_pqWidget->resize(iWidthWidget,iHeightWidget);
    13. ...
    14.  
    15. //Here I want to force "this"(dialog) to fit the widgets size.
    16. }
    To copy to clipboard, switch view to plain text mode 


    Quote Originally Posted by jpn View Post
    Well, why do you care about the dialog size when the aspect ratio of the content is correct?
    Because I want to force the Widget to be 640 width and Y width(that depends on the aspect ratio).

    Thanks,
    Òscar Llarch i Galán

  10. #10
    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: Resize widget force layout resizing

    Quote Originally Posted by ^NyAw^ View Post
    The widget not will resize itself.
    I said you have to implement sizeHint(), not to call resize(). The latter has no effect together with QLayout::SetFixedSize. The layout will follow the size hint, strictly.
    J-P Nurmi

  11. #11
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Resize widget force layout resizing

    Hi,

    Qt Code:
    1. myLayout::myLayout(...)
    2. {
    3. ...
    4. this->layout()->setSizeConstraint(QLayout::SetFixedSize);
    5. ...
    6. }
    7.  
    8. QSize myWidget::sizeHint()
    9. {
    10. //Here I have to calculate the size -> 640xY
    11. }
    To copy to clipboard, switch view to plain text mode 
    The "sizeHint" method of myWidget is never called.

    I don't really understand "sizeHint" behaviour, maybe because I'm not english and don't understand it's function.

    See the attached image. I have this dialog and I use the QWidget(that is difficult) to see(it is on top of the other widgets). I use this QWidget as the parent of my widget(because I have not created the QtDesigner plugin).

    Thanks,
    Attached Images Attached Images
    Last edited by ^NyAw^; 10th February 2009 at 17:57. Reason: Atacched image forget!
    Òscar Llarch i Galán

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Replies: 5
    Last Post: 25th May 2008, 08:22
  3. Move and resize with layout
    By waediowa in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2008, 08:16
  4. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  5. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00

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.