Results 1 to 3 of 3

Thread: creating different types of mdi children

  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default creating different types of mdi children

    I've wrote a generic method which should create mdi children. the central widgets of the created mdi children have different classes and I think it does not work as expected because everything is "casted down to QWidget*"

    it does not work as expected in that the mdi child is created, but the central widget is empty (it does not have the controls I'd expect it to have)

    Here's the code I consider relevant
    Qt Code:
    1. //------------------------------------------
    2. #include "SubWindowObjects.h"
    3. #include "utils.h"
    4.  
    5. SubWindowObjects::SubWindowObjects(QToolBar* bar, QWidget* widget,QString *title, QMdiArea* mdiArea) {
    6. dbg();
    7. this->subWindow = new QMdiSubWindow(widget);
    8. this->switchButton = new QPushButton(*title);
    9. this->switchAction = bar->addWidget(this->switchButton);
    10. this->switchAction->setVisible(false);
    11. this->mdiArea = mdiArea;
    12. this->mdiArea->addSubWindow(this->subWindow);
    13. this->subWindow->hide();
    14. }
    15.  
    16. SubWindowObjects::~SubWindowObjects() {
    17. //TODO delete objects
    18. }
    19.  
    20. void SubWindowObjects::show() {
    21. this->switchAction->setVisible(true);
    22. this->subWindow->show();
    23. }
    24. void SubWindowObjects::hide() {
    25. this->switchAction->setVisible(false);
    26. this->subWindow->hide();
    27. }
    28. //------------------------------------------
    29. SoftpediaClient::SoftpediaClient(QWidget *parent)
    30. : QMainWindow(parent)
    31. {
    32. ui.setupUi(this);
    33. this->mdiArea = new QMdiArea(this);
    34. setCentralWidget(this->mdiArea);
    35. this->switchBar = new QToolBar(tr("Switch Bar"));
    36. this->switchBar->setMinimumWidth(100);
    37. addToolBar(Qt::LeftToolBarArea,this->switchBar);
    38. dbg();
    39. this->subwindows["login"] = new SubWindowObjects(this->switchBar,new LoginDialog(this->mdiArea),new QString("Login"),this->mdiArea);
    40. dbg();
    41. this->subwindows["login"]->hide();
    42. dbg("init");
    43. }
    44. //------------------------------------------
    45. LoginDialog::LoginDialog(QWidget *parent)
    46. : QDialog(parent)
    47. {
    48. ui.setupUi(this);
    49. }
    To copy to clipboard, switch view to plain text mode 
    SubWindowObjects aggregates gui elements which are related to each other (ie the button on a tool bar, the action bound to it, the mdi child, and maybe more to come)
    on line 5, QWidget* widget will be the central widget of the mdi child, but I'm obviously missing something

    maybe I'm doing it wrong on line 39, but the object should not be wiped out from the heap, ie: new LoginDialog(this->mdiArea)

    I've attached the complete project.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: creating different types of mdi children

    I was making a stupid mistake. Fixed.

    correct:

    Qt Code:
    1. SubWindowObjects::SubWindowObjects(QToolBar* bar, QWidget* widget,const char *title, QMdiArea* mdiArea) {
    2. dbg("creating %s",title);
    3. this->switchButton = new QPushButton(title);
    4. this->switchAction = bar->addWidget(this->switchButton);
    5. this->switchAction->setVisible(false);
    6. this->mdiArea = mdiArea;
    7. this->subWindow = this->mdiArea->addSubWindow(widget);
    8. this->subWindow->hide();
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: creating different types of mdi children

    I have been doing something similar in qmdilib ;-)
    Take a look: http://code.google.com/p/qtedit4/wiki/qmdilib

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.