0
votes

What I'm trying to accomplish:

Create 2 classes that inherit QVBoxLayout simply to set up each class with a series of different objects.

e.g.: Class 1 (inherits QVBoxLayout), has QLabels to show an appointment and those labels set up with this->addWidget(labels);

Class 2 (inherits QVBoxLayout), has QLineEdits (and so on) to edit an appointment and those objects are also set up with this->addWidget(lineedits);

Is it possible to have a QWidget class then switch between these 2 layouts by calling this->setLayout(class1_object); and this->setLayout(class2_object);?

Or how would you suggest the swapping of the active objects on the widget (when clicking the edit button on the view-part or the save button on the edit-part)?

Simply use object->setShown(false);?

1

1 Answers

1
votes

IMO, it's easier to use QTabWidget here. Make a QTabWidget with 2 tabs. On Tab1, put your labels. On Tab2, put your edits. Call Tab2 something like "Edit the appointment". Now, use the currentChanged() slot for catching the tab switching.

If saving edits should be simple, all you will need to do is just to copy the edited data from edits to labels, and vice-versa.

If saving requires more than that, e.g. you want a confirmation dialog, you can permit the user to change back to Tab1 until some condition is met:

void MainWindow::on_tabWidget_currentChanged(int index)
{
    //if the user is trying to go back to Tab1 (where the labels are)...
    if(index == 0)
    {
         //...and if user didn't accept something, we just return him to the current tab
         //It's probably a good idea to tell him what went wrong, too :P
         if(!userAcceptedSaveDialog())
             ui.tabWidget.setCurrentIndex(1);        
    }
}