[Qt4]"Dynamische" Layouts



  • Hallo alle miteinander,

    ich habe derzeit ein großes Problem in meinem Projekt:

    Ich habe einen QFrame, dessen Layout sich im Verlauf des Programms ändert.
    Sprich:
    Am Anfang hat er ein leeres Layout, dann wird ihm ein anderes Layout zugewiesen, und dann wieder nen anderes, etc.

    Das Problem ist, dass er die Änderung nicht annimmt. Er bleibt stets bei seinem alten Layout.
    Hier die Code-Auszüge:
    Header:

    QFrame *modulFrame;
    QLabel *mainDummyLabel;
    QLabel *modulLabel;
    QVBoxLayout *modulLayout;
    QVBoxLayout *mainDummyLayout;
    

    Konstruktor:

    modulLabel = new QLabel(tr("<h2>Module</h2>"));
    modulLayout = new QVBoxLayout();
    modulFrame = new QFrame();
    mainDummyLabel = new QLabel("MainFrame");
    mainDummyLayout = new QVBoxLayout();
    mainDummyLayout->addWidget(mainDummyLabel);
    modulFrame->setLayout(mainDummyLayout);
    

    Neues Layout:

    QLayoutItem *child;
    while ((child = modulLayout->takeAt(0)) != 0)
    {
        delete child;
    }
    Layout *toDelete = modulFrame->layout();
    if(toDelete!=0)
    {
        delete toDelete;
    }
    
    modulLayout = new QVBoxLayout();
    
    modulLayout->addWidget(modulLabel);
    modulLayout->addStretch(1);
    
    for(int i=0;i<modulList->size();i++)
    {
        modulLayout->addWidget(modulList->at(i)->modulCheck);
    }
    modulLayout->addStretch(3);
    
    modulFrame->setLayout(modulLayout);
    

    Hat jemand eine Idee, wie man so etwas realisieren sollte?

    Danke im Voraus und Ciao,

    Prof. MAAD


Anmelden zum Antworten