Results 1 to 7 of 7

Thread: Manually adjust geometry in custom widget

  1. #1
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Manually adjust geometry in custom widget

    I have a subclassed widget that I paint on. What I want to do is is click on a zoom in button and have the widget expand horizontally. Right now what happens is I click on zoom in and the widget stays the same size. Here is a snippet of what I am currently doing with the resizing.

    Qt Code:
    1. Chart::Chart(QWidget *parent) : QWidget(parent)
    2. {
    3. setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding);
    4. setGeometry(0,0,base_width,base_height);
    5. }
    6.  
    7. Chart::set_resize(int w, int h)
    8. {
    9. QSize size(w,h);
    10. resize(size);
    11. }
    To copy to clipboard, switch view to plain text mode 
    What am I doing wrong?
    Any suggestions?

    Thank You
    Last edited by jpn; 19th June 2008 at 04:47. Reason: missing [code] tags

  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: Manually adjust geometry in custom widget

    Is it in a layout?
    - Custom Widgets in Layouts
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Manually adjust geometry in custom widget

    it is in a layout

  4. #4
    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: Manually adjust geometry in custom widget

    Quote Originally Posted by Rooster View Post
    it is in a layout
    You don't resize widgets by hand when they are in a layout. The layout is responsible for maintaining their geometries. Just read the link I gave, layouts resize widgets according to those rules listed in the documentation.
    J-P Nurmi

  5. #5
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Manually adjust geometry in custom widget

    Ok,

    I created a custom layout similar to what is in the link. I placed the widget in the layout and now I want to expand the layout/widget size when I click on a button to zoom in. How do I get the layout to expand when I click this button. Also, once the width get to a certain size, how do I get it to stop expanding and add a scroll bar so I can scroll over.

  6. #6
    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: Manually adjust geometry in custom widget

    Quote Originally Posted by Rooster View Post
    I placed the widget in the layout and now I want to expand the layout/widget size when I click on a button to zoom in. How do I get the layout to expand when I click this button.
    If the widget is in a layout, call QWidget::updateGeometry() to notify the layout system that sizeHint() or sizePolicy() of that widget has changed. If you place it inside a scroll area like adviced below, you may call QWidget::adjustSize().

    Also, once the width get to a certain size, how do I get it to stop expanding and add a scroll bar so I can scroll over.
    Place the widget inside a QScrollArea.
    J-P Nurmi

  7. #7
    Join Date
    Feb 2008
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Manually adjust geometry in custom widget

    Thank you for the advise everthing works great now.

Similar Threads

  1. Custom Widget - First Steps
    By sekatsim in forum Qt Programming
    Replies: 8
    Last Post: 26th June 2008, 17:19
  2. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  3. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  4. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  5. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12

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.