Results 1 to 3 of 3

Thread: Create QMainWindow in runtime

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Create QMainWindow in runtime

    Hi all,

    I want to create a QMainWindow when I click in a QPushButton.

    I have this code in the SLOT of the QPushButton that is called when the clicked() SIGNAL is emitted:

    Qt Code:
    1. QMainWindow* myQMainWindow = new QMainWindow(this);
    2. myQMainWindow->setWindowModality(Qt::WindowModal);
    3. myQMainWindow->setGeometry(geometry());
    4. myQMainWindow->move(QPoint(100, 100));
    5.  
    6. QVBoxLayout *layout = new QVBoxLayout(myQMainWindow->centralWidget());
    7. myQMainWindow->setLayout(layout);
    8. QPushButton* pushButton = new QPushButton("hello", myQMainWindow->centralWidget());
    9. myQMainWindow->show();
    To copy to clipboard, switch view to plain text mode 

    The window appears but the button with text "hello" doesn't shown. Why?

    Regards.

  2. #2
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Create QMainWindow in runtime

    Maybe you have to add button to layout?

  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Create QMainWindow in runtime

    I have solved it.

    I have created a QWidget and I have called to QMainWindow::setCentralWidget() method.

    Regards.

Similar Threads

  1. Replies: 3
    Last Post: 13th November 2011, 08:12
  2. Replies: 2
    Last Post: 29th June 2011, 15:45
  3. How to change QMainWindow size at runtime?
    By myfifth in forum Newbie
    Replies: 11
    Last Post: 10th January 2011, 06:18
  4. Replies: 1
    Last Post: 25th September 2010, 08:20
  5. How do I create an Object at runtime?
    By Cayan in forum Newbie
    Replies: 2
    Last Post: 28th June 2010, 07:01

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.