Results 1 to 7 of 7

Thread: Open a window inside another window

  1. #1
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Open a window inside another window

    Hello,
    I'd like to know how can I open a window embedded in another one. More specifically I want to open a window in a determined part of another window when I click in a button. And I don't know what object I can use to open a window inside it.
    Thank in advance

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Open a window inside another window

    if 'window' means a Qt widget, have a look at QMdiArea

  3. #3
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Smile Re: Open a window inside another window

    If u means this:

    Qt Code:
    1. class MainWindow : public QWidget
    2. {
    3. public:
    4. MainWindow(QWidget *parent = 0);
    5.  
    6. private slots:
    7. void newWindow();
    8.  
    9. private:
    10. QWidget *newWindow;
    11. };
    12.  
    13. MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
    14. {
    15. QPushButton *n = new QPushButton("new Window");
    16. n->show();
    17. connect(n,SIGNAL(clicked()),this,SLOT(newWindow()));
    18. }
    19.  
    20. int main(int argv, char *argc[])
    21. {
    22. QApplication app(argv,argc);
    23.  
    24. MainWindow mW;
    25.  
    26. mW.show();
    27. app.exec();
    28. }
    29.  
    30. void MainWindow::newWindow()
    31. {
    32. newWindow = new QWidget;
    33.  
    34. newWindow->setGeometry(QRect(100,100,300,300));
    35. newWindow->setWindowTitle("new Window");
    36. newWindow->show();
    37. }
    To copy to clipboard, switch view to plain text mode 
    ...

  4. The following user says thank you to Peppy for this useful post:

    passerb (17th October 2009)

  5. #4
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Open a window inside another window

    Thank you for your answer. You help me a lot

  6. #5
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Open a window inside another window

    I tried this by this way: (I'm using PyQt4)

    - I generated a MainWindow using Qt Design with a widget object where I want to load another widget

    - I generated a Widget using Qt Design with a simple button

    Like this:

    #class widget that I want to be loaded
    Qt Code:
    1. class a(object):
    2. def setupUi(self, Form):
    3. Form.setObjectName("Form")
    4. self.btModificar = QtGui.QPushButton(self.centralwidget)
    5. self.btModificar.setGeometry(QtCore.QRect(280, 40, 91, 21))
    6. self.toolBox.setCurrentIndex(0)
    To copy to clipboard, switch view to plain text mode 


    #class that I want to load the widget
    Qt Code:
    1. class Ui_MainWindow(object):
    2. def setupUi(self, MainWindow):
    3. MainWindow.setObjectName("MainWindow")
    4. self.centralwidget = QtGui.QWidget(MainWindow)
    5. self.centralwidget.setObjectName("centralwidget")
    6. self.btAdicionar = QtGui.QPushButton(self.centralwidget)
    7. self.btAdicionar.setGeometry(QtCore.QRect(90, 40, 91, 21))
    8. self.btAdicionar.setObjectName("btAdicionar")
    9. self.widget = QtGui.QWidget(self.centralwidget)
    10. self.widget.setGeometry(QtCore.QRect(160, 105, 811, 471))
    11. self.widget.setObjectName("widget")
    12. MainWindow.setCentralWidget(self.centralwidget)
    13. QtCore.QObject.connect(self.btAdicionar, QtCore.SIGNAL("clicked()"), MainWindow.adicionar)
    To copy to clipboard, switch view to plain text mode 


    # thats the class that implements the Ui_MainWindow
    Qt Code:
    1. class MainWindow (QMainWindow, Ui_MainWindow):
    2.  
    3. def __init__(self, parent=None):
    4. super(MainWindow, self).__init__(parent)
    5. self.setupUi(self)
    6.  
    7. def adicionar(self):
    8. # here I want to load that widget named a
    9. # I tried this:
    10. # aa = a()
    11. # self.widget.setParent(aa)
    12. # self.widget.show()
    13. # but it didnt work
    To copy to clipboard, switch view to plain text mode 
    Last edited by passerb; 18th October 2009 at 02:11.

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Open a window inside another window

    Instead of positioning all your widgets yourself by using setGeometry, you should use layouts! It is much more easier that way. And to layouts you can easily add other widgets - even on runtime - using QLayout::addWidget().

  8. #7
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Open a window inside another window

    I did it!! Thank you very much
    I could using QLayout::addWidget() like you said

Similar Threads

  1. open a video file in a new window...
    By jiapei100 in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 15:53
  2. Replies: 2
    Last Post: 9th August 2009, 23:08
  3. Best way to open a Qt window from web page?
    By montylee in forum Qt Programming
    Replies: 9
    Last Post: 19th January 2009, 09:04
  4. Storing window geometry inside XML file.
    By GuS in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2008, 14:42
  5. right way to open a new window
    By wind in forum Newbie
    Replies: 1
    Last Post: 1st November 2006, 12:17

Tags for this Thread

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.