Results 1 to 9 of 9

Thread: maximizing own widget on parent

  1. #1
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy maximizing own widget on parent

    Hi all,

    I've made a class based on QWidget and it needs another QWidget as parent.
    Qt Code:
    1. Map::Map( QWidget *parent ) : QWidget(parent)
    To copy to clipboard, switch view to plain text mode 
    Now I designed a window in QtDesigner and I subclassed the ui code and on a frame that I placed using QtDesigner the map is placed:
    Qt Code:
    1. map = new Map(ui.frameMain);
    To copy to clipboard, switch view to plain text mode 
    Next step would be to draw on the map using the paint event. However.. if I draw a line from the topleft to bottomright corner of the map it only takes up a small part of the parent (the frame).

    How can I make the map always use the available space of the frame?

    Thanks in advance!
    Rob

    ps. I tried setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding); in the constructor but that didn't work

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Add a layout to ui.frameMain.

  3. #3
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    It works.. thanks jacek!

    this is what I added to the constructor of the main window

    Qt Code:
    1. map = new Map(ui.frameMain);
    2. m_layoutMain = new QHBoxLayout;
    3. m_layoutMain->addWidget(map);
    4. ui.frameMain->setLayout(m_layoutMain);
    To copy to clipboard, switch view to plain text mode 

    I still got one question though.. is it possible to access layouts that were create using QtDesigner? I added one to the main form but after using this code
    Qt Code:
    1. ui.frameMain->layout()->addWidget(map);
    To copy to clipboard, switch view to plain text mode 
    the application crashes at creation.

    Again.. thanks in advance

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Check pointers that you use..have you add widget after create it ?
    Also check what return ui.frameMain->layout()
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Quote Originally Posted by masoroso
    is it possible to access layouts that were create using QtDesigner? I added one to the main form
    It should be possible.

    Quote Originally Posted by masoroso
    but after using this code [...] the application crashes at creation.
    Did you invoke ui.setupUi() before that line?

  6. #6
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    It should be possible.
    this is the code:

    Qt Code:
    1. MainForm::MainForm(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. //setup signals and slots created in QtDesigner
    5. ui.setupUi(this);
    6.  
    7. //create a map
    8. map = new Map(ui.frameMain);
    9. //ui.frameMain->layout()->addWidget(map); //not sure why this didn't work :-/
    10. QLayout* l = ui.frameMain->layout();
    11.  
    12. qDebug() << l;
    To copy to clipboard, switch view to plain text mode 

    The debug line gives 'QObject(0x0)'.. so it's empty

    EDIT..
    if I use a button and then try to access the layout it does work ([2148] DEBUG: in loadFile QLayout: QHBoxLayout(0x11874e0)
    ) so I guess I need to access the layout at form showup and not at creation? Any advice on which event to use then (a QMainWindow event or a timer?)
    Last edited by masoroso; 21st April 2006 at 12:23.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Are there any widgets on that ui.frameMain widget (except for that map)? Maybe you haven't set any layout for it in the Qt Designer?

  8. #8
    Join Date
    Apr 2006
    Location
    the netherlands
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Are there any widgets on that ui.frameMain widget (except for that map)? Maybe you haven't set any layout for it in the Qt Designer?
    I have a dockwidget, a layout and a frame on the form. I first dropped the layout on the form (QHboxLayout) and then dropped the frame on it. The dockwidget is placed left of the other widgets and the dockwindow is not part of the layout.

    What I do not understand is why it is not possible to access the layout because you cannot give layouts a name in QtDesigner. If you look at the generated ui code the layout *has* a name so you could use this name in the subclassing code.

    I presume it is possible to access the layouts by using the layout() function but I also presume this is only possible if the window has been made visible because then they are actualy created.. ? It remembered me of Delphi's onCreate and onShow event of a TForm which als had these `problems'. Now I only need to find a event that occurs only once at startup (or add a boolean to trigger the setting of the layout..).

    I'll puzzle some more

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: maximizing own widget on parent

    Quote Originally Posted by masoroso
    I have a dockwidget, a layout and a frame on the form. I first dropped the layout on the form (QHboxLayout) and then dropped the frame on it. The dockwidget is placed left of the other widgets and the dockwindow is not part of the layout.
    If I got you right, you haven't set any layout for the frameMain frame, only for its parent.

    BTW. Layouts listed in the "Widget Box" are not pure layouts, but rather widgets with a given layout. Better use "Lay Out ..." actions from the Form menu/toolbar.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  3. Replies: 6
    Last Post: 3rd September 2008, 14:27
  4. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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.