Results 1 to 7 of 7

Thread: Simple Mdi question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Location
    Serbia, Sabac
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Simple Mdi question

    I know it's been more than a year since the last post, but I don't think I should open another threat because of that.

    Quote Originally Posted by ChrisW67 View Post
    The grandparent of the first widget, if it exists, can be cast to QMdiArea to add another widget...
    Can you be more specific about how to do that? Maybe a short example would help..

    What I have is QMainWIndow as a parent, QMdiArea as a central widget. User opens form2 from the menu bar, and its added to QMdiSubWindow. If the users clicks the button on form2, it should open form3 and it should be added to QMdiSubWindow also.

    Thank you for your help,
    Dejan

  2. #2
    Join Date
    May 2012
    Location
    Serbia, Sabac
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Simple Mdi question

    Anyone ?
    Dejan

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Simple Mdi question

    I think you should prefer using a signal. Here is one of many ways to organise this:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class PushButton: public QPushButton
    4. {
    5. Q_OBJECT
    6. public:
    7. PushButton(QWidget *p = 0): QPushButton(p) {
    8. connect(this, SIGNAL(clicked()), SLOT(doClicked()));
    9. }
    10.  
    11. private slots:
    12. void doClicked() {
    13. QTextEdit *edit = new QTextEdit(this); // could be any widget
    14. emit addAnotherMdiChild(edit);
    15. }
    16.  
    17. signals:
    18. void addAnotherMdiChild(QWidget *child);
    19. };
    20.  
    21.  
    22. class MainWindow: public QMainWindow
    23. {
    24. Q_OBJECT
    25. public:
    26. MainWindow(QWidget *p = 0): QMainWindow(p) {
    27. m_area = new QMdiArea(this);
    28. setCentralWidget(m_area);
    29.  
    30. PushButton *button = new PushButton(this);
    31. button->setText("Add another widget");
    32. connect(button, SIGNAL(addAnotherMdiChild(QWidget *)), SLOT(doAddAnotherMdiChild(QWidget *)));
    33. doAddAnotherMdiChild(button);
    34. }
    35.  
    36. public slots:
    37. void doAddAnotherMdiChild(QWidget *child) {
    38. (void) m_area->addSubWindow(child);
    39. child->show();
    40. }
    41.  
    42. private:
    43. QMdiArea *m_area;
    44. };
    45.  
    46.  
    47. int main(int argc, char **argv) {
    48. QApplication app(argc, argv);
    49.  
    50. MainWindow w;
    51. w.show();
    52. return app.exec();
    53. }
    54. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

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

    gojkovicde (17th December 2012)

  5. #4
    Join Date
    May 2012
    Location
    Serbia, Sabac
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple Mdi question

    Thank you for the advice and example, I'll get into details of it as soon as I can..
    Dejan

Similar Threads

  1. Simple question
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2011, 12:42
  2. simple MVC question!
    By landonmkelsey in forum Qt Programming
    Replies: 14
    Last Post: 19th August 2008, 12:25
  3. A simple question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 6th April 2007, 08:54
  4. simple question
    By mickey in forum Newbie
    Replies: 2
    Last Post: 20th June 2006, 10:39
  5. Another simple question...
    By Dark_Tower in forum Newbie
    Replies: 5
    Last Post: 31st March 2006, 16: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
  •  
Qt is a trademark of The Qt Company.