¿Es posible heredar QVBoxLayout y configurarlo como diseño en QWidget?

Lo que estoy tratando de lograr:

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); y 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)?

Sólo tiene que utilizar object->setShown(false);?

preguntado el 31 de julio de 12 a las 14:07

1 Respuestas

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

Respondido 31 Jul 12, 14:07

I see where you are going with that, interesting. Is it possible to hide the tab labels? I mean: hide the fact that they are tabs and just switch between them with signals bound to buttons? - El tipo respeta

@thedudeabides, you probably cant "hide" them. But each tab contains a widget. So you can store two widgets, delete all the tabs from the TabWidget, and then when you need to show a particular tab, use tabWidget->addTab(), and when you need to hide it, use tabWidget->removeTab(). - SingerOfTheFall

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.