Results 1 to 4 of 4

Thread: addWidget other place than setCentralWidget()

  1. #1
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default addWidget other place than setCentralWidget()

    Qt Code:
    1. void MainWindow::setGUI()
    2. {
    3. QWidget* frame = new QWidget;
    4. QToolButton *toolButton;
    5. _layout = new QVBoxLayout;
    6. frame->setLayout(_layout);
    7. tabWidget = new QTabWidget();
    8. tab = new QWidget();
    9. pushButton = new QPushButton(tab);
    10. tabWidget->addTab(tab, QString());
    11. _layout->addWidget(tabWidget);
    12. scrollArea = new QScrollArea;
    13. scrollArea->setWidget(frame);
    14. scrollArea->setWidgetResizable(true);
    15. setCentralWidget(scrollArea);
    16. }
    To copy to clipboard, switch view to plain text mode 
    This above works fine, i got scrollArea->tabWidget->tab->pushButton, but if I'd like to addWidget from other method/function to this layout i am not able to add new widget to "tab". Everything is under tabWidget which is part of scrollArea (centralWidget).
    Qt Code:
    1. void MainWindow::addToGUI()
    2. {
    3. while(true)
    4. {
    5.  
    6. QGroupBox* newGB = new QGroupBox("group box");
    7. QFormLayout* form_layout = new QFormLayout;
    8.  
    9. layout->addRow("ID1", new QLabel(function()));
    10. layout->addRow("ID2", new QLabel(function()));
    11. layout->addRow("ID3", new QLabel(function()));
    12.  
    13. newGB->setLayout(layout);
    14. this->_layout->addWidget(newGB); // i want this in tabWidget->tab, i know that there is setCentralWIdget(scrollArea) and that is why i get this under tabWidget.
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    Here is what i mean -> 84465788e05d.jpg

    How to solve this?

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: addWidget other place than setCentralWidget()

    Just add needed widgets to QTabWidget's tab (better place layout there), not to main window's layout.
    Oleg Shparber

  3. #3
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: addWidget other place than setCentralWidget()

    Quote Originally Posted by Oleg View Post
    Just add needed widgets to QTabWidget's tab (better place layout there), not to main window's layout.
    I'm QT noob, and i'm not sure what u mean. since a few yeras i only use php oop.
    I removed this line "this->_layout->addWidget(newGB);" from addToGUI(), and wrote "_layout->addWidget(newGB);" in setGUI() but I got app crash, that exe is not responding (headers are correct).

  4. #4
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: addWidget other place than setCentralWidget()

    1. BTW, create all widgets in visual editor, it's much easier.
    2. Add layout to your tab
    Qt Code:
    1. tab->setLayout(new QVBoxLayout());
    To copy to clipboard, switch view to plain text mode 
    3. Add QPushButton and QGroupBox to that layout
    Qt Code:
    1. tab->layout()->addWidget(new QPushButton());
    2. tab->layout()->addWidget(newGB);
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

  5. The following user says thank you to Oleg for this useful post:

    darkrptyp (19th November 2011)

Similar Threads

  1. Replies: 1
    Last Post: 19th March 2011, 11:57
  2. setCentralWidget problems
    By tlerner in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2009, 22:26
  3. QGraphicsScene::addWidget on MAC OS X 10.5.8
    By marcomas in forum Qt Programming
    Replies: 4
    Last Post: 23rd August 2009, 20:37
  4. QStatusBar::addWidget() without Frame
    By Lykurg in forum Newbie
    Replies: 2
    Last Post: 25th April 2006, 14:46
  5. addWidget in qWidgetStack
    By mickey in forum Newbie
    Replies: 7
    Last Post: 3rd March 2006, 22:09

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.