PDA

View Full Version : Single widget for different datatypes



caster89
21st March 2015, 20:08
Hi everyone,
I have a question on the best way to program a widget which is supposed to change based on the datatype it has to show.
Basically i am trying to create the interface to an interface for a small database which ideally contains four types of data: Text-Long Text - Single Image - Multiple Images the four types are displayed using QLineEdit-QTextEdit-QLabel-QListWidget. What i am doing right now is I created a QWidget subclass which creates a different QWidget using a switch statement, and which handles the READ and WRITE functions for the value, which allows me to use the widget with a mapper. Can anyone suggest a better solution for this situation, something which would allow me to have one programmatic interface (READ and WRITE for a mapper) but at the same type have a fixed number of user interfaces the different types.
I solved a similar problem by using a base class, different child classes and a handle class which stores a pointer declared to the base class and initialized to the appropriate derived class, but I am not sure of how to implement it using a QWidget.