Results 1 to 8 of 8

Thread: addWidget in qWidgetStack

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Unhappy addWidget in qWidgetStack

    Hi,
    I need to add a widget on a widgetstack (and work!) but I need it is 1/2 of widgetStack (insert from Designer)
    Qt Code:
    1. MyWidget top (&w, "top");
    2. top.setGeometry(QRect(0,0,w.WidgetStack->width()/2,w.WidgetStack->height()) );
    3. int shared_top= w.WidgetStack->addWidget(&top);
    4. cout << w.WidgetStack->width() << endl;
    5. cout << w.WidgetStack->height() << endl;
    To copy to clipboard, switch view to plain text mode 
    Why doesn't it work? (cout print 101 and 31 (why 31? Should be much more))
    Thanks....
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: addWidget in qWidgetStack

    It won't work this way. The widget always occupies the whole widget stack geometry. You have to use layouts, spacers, sizeHints and sizePolicies to alter the behaviour.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: addWidget in qWidgetStack

    yes thanks. I try this way but layout don't appear on myWidgetstack..
    Qt Code:
    1. MyWidget top (&w, "top shared", w.myWidget1);
    2. QBoxLayout *layout = new QHBoxLayout(w.WidgetStack, 5, 0, "top" );
    3. layout->addWidget(&top);
    To copy to clipboard, switch view to plain text mode 
    I need to take w parent of top.
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: addWidget in qWidgetStack

    Layout needs to be assigned to a widget. Something like this:

    Qt Code:
    1. QWidget *w = new QWidget(this);
    2. //...
    3. QWidget *chld = new QWidget(this);
    4. l->addWidget(chld);
    5. //...
    6. w->setLayout(l);
    7. //...
    8. stackedWidget->addWidget(w);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: addWidget in qWidgetStack

    Sorry but my 'w' is: MainForm w;
    Quote Originally Posted by wysota
    Qt Code:
    1. QWidget *w = new QWidget(this);
    2. QWidget *chld = new QWidget(this);
    3. l->addWidget(chld);
    4. w->setLayout(l);
    5. stackedWidget->addWidget(w);
    To copy to clipboard, switch view to plain text mode 
    In anyway, your code get this error:
    Qt Code:
    1. error C2248: 'QWidget::setLayout' : cannot access private member declared in class 'QWidget'
    To copy to clipboard, switch view to plain text mode 
    I am in main.cpp...
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: addWidget in qWidgetStack

    Quote Originally Posted by mickey
    I am in main.cpp...
    This should not be done there Setting layouts should be done in the constructor of a widget. Nevertheless QWidget::setLayout() is public... Aa... you're using Qt3. Then setting the widget as a parent to a layout should be enough.
    Last edited by wysota; 3rd March 2006 at 12:19.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: addWidget in qWidgetStack

    Sory your code don't compile, maybe bacause my widget is a QGLWidget and I put it in costructor of myGLWidget....
    Qt Code:
    1. QWidget *w = new QWidget(this);
    2. QWidget *chld = new QWidget(this);
    3. l->addWidget(chld);
    4. //w->setLayout(l);
    To copy to clipboard, switch view to plain text mode 
    If I comment last istruction don't display.....
    Last edited by mickey; 3rd March 2006 at 14:37.
    Regards

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: addWidget in qWidgetStack

    HI, this code seems ok. But it don't put 'l' on widget w. w->setlayout(l) don't compile.
    Qt Code:
    1. QWidget *w = new QWidget;
    2. QHBoxLayout *l = new QHBoxLayout(this);
    3. l->addWidget(top);
    4. //...........
    5. this->WidgetStack->addWidget(w);
    To copy to clipboard, switch view to plain text mode 
    myGLWidget 'top appear in a small square on toolbar. I don't know how put it on widget w.
    Any hints?
    Regards

Similar Threads

  1. Replies: 1
    Last Post: 19th April 2007, 16:56
  2. QWidgetStack
    By cpepe in forum Qt Programming
    Replies: 2
    Last Post: 31st March 2006, 16:26

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.