Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] how to have only one instance of a tab in MDIarea
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] how to have only one instance of a tab in MDIarea

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arsinte_andrei
    wrote on last edited by
    #1

    The problem that I'm facing at the moment is hw can I have only one instance of a tab in mdi area.
    @void AtpMainWindow::onActCompEditCompany(){
    //FIXME only one tab of company editor - no need of many to be opened
    /*
    AtpCompanyEdit *mdiChild;

    foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
    mdiChild = qobject_cast<AtpCompanyEdit *>(window->widget());

    }
    if(mdiChild){
    mdiArea->setActiveSubWindow(mdiChild);
    } else {
    */
    AtpCompanyEdit *companyEditor = new AtpCompanyEdit;
    companyEditor->setAttribute(Qt::WA_DeleteOnClose);
    //possible windows to close
    connect(companyEditor, SIGNAL(exitSignal()), actFileClose, SLOT(trigger()));
    mdiArea->addSubWindow(companyEditor);
    companyEditor->show();
    companyEditor->activateWindow();
    // }
    }@

    this is what I have at the moment... is working fine except that if the user want to open 100 tabs nothing is stopping him from that. also this is editing a SQLite dataBase and I do not want in one tab to delete a company and in another tab to edit the same company... so I will need only one tab for this. my idea is to have like an id or something like that because I have classes that will need to open many times like a list of invoices where a user can click on invoice and open up it's details (based on id he can open many invoice details at once but only one of same id)
    any help... Highly appreciated..
    thanks
    Andrew

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Just make it a member variable, create in the constructor and only show it in onActCompEditCompany

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arsinte_andrei
        wrote on last edited by
        #3

        yep I've tried that and is working but the second problem is not sorted out

        • my idea is to have like an id or something like that because I have classes that will need to open many times like a list of invoices where a user can click on invoice and open up it’s details (based on id he can open many invoice details at once but only one of same id)
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can keep a QVector of opened record, since every invoices will have a unique primary key you can use it for identification.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arsinte_andrei
            wrote on last edited by
            #5

            good point... I will try it in few moments and I'll let you know the result. Thanks for now...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              arsinte_andrei
              wrote on last edited by
              #6

              ok... is working but what is the impact on the memory??

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                It depends on how you manage your vector. It should not contain more element that the number of current opened records.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  arsinte_andrei
                  wrote on last edited by
                  #8

                  yes this it will be a bit difficult to implement it but I hope at the end to get a good management on tab closer. the thing is that I have always to keep the vector or in my idea a QMap<QString, QWidget>, synchronised. but I'll think about because every class that I have is a class that extended QWidget @class ATPCOMPANY_EXPORT AtpCompanyGroupPlace : public QWidget@ or @class ATPCLIENT_EXPORT AtpClientInvoices : public QWidget@.
                  Ok.thanks.. I'll mark it Solved as this is an obvious solution (I do not know if this is the only one... but... I will further search or research )
                  Thanks for your help..... you can have a look at "github":https://github.com/arsinte-andrei/electricity in order to see the project that I'm speaking about

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    arsinte_andrei
                    wrote on last edited by
                    #9

                    @void AtpMainWindow::onActCompEditCompany(){

                    AtpCompanyEdit *mdiChild;

                    foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
                    mdiChild = qobject_cast<AtpCompanyEdit *>(window->widget());
                    if(mdiChild){
                    mdiArea->setActiveSubWindow(window);
                    return;
                    }
                    }

                    AtpCompanyEdit *companyEditor = new AtpCompanyEdit;
                    companyEditor->setAttribute(Qt::WA_DeleteOnClose);
                    //possible windows to close
                    connect(companyEditor, SIGNAL(exitSignal()), actFileClose, SLOT(trigger()));
                    mdiArea->addSubWindow(companyEditor);
                    companyEditor->show();
                    companyEditor->activateWindow();
                    }@

                    this is looking to be also a solution without using a Vector and without to maintain a vector. this is iterating all the mdiArea subwindows and check for my class if is opened. if it is then it just bring it up. - found it in the MDI example that came with Qt

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved