PDA

View Full Version : Acces a stacked widget...?



ucomesdag
25th November 2006, 13:10
I 'm was looking at the Config Dialog example (http://doc.trolltech.com/4.2/dialogs-configdialog.html)
and was wondering how to get the data to use in the main function.

I want to use something similar but don't see how to acces the data.

Thanks

jacek
25th November 2006, 13:21
This is a made up example, so you can't access data easily, but in normal situation all *Page widgets would keep pointers to their children, so that you can read the settings. You can also add read() and write() methods that would read/store those settings in application's configuration.

ucomesdag
25th November 2006, 13:36
Is there someway to do it like this dialog->pagesWidget->currentWidget()?

jacek
25th November 2006, 13:45
Is there someway to do it like this dialog->pagesWidget->currentWidget()?
Of course there is, but the question is whether you are going to use something like this:
QString something = (static_cast< SomeConfigPage* >(dialog->pagesWidget->currentWidget()))->ui.someLineEdit->text();
throughout your code, or do you want to do it in a more elegant way?

ucomesdag
25th November 2006, 13:52
What would be more elegant?

jacek
25th November 2006, 14:05
What would be more elegant?
You can create a ConfigDialog that displays ConfigPages. All ConfigDialog need to know is that what ConfigPages it contains, which one is the current one and which one should become the current one if user selects some item in the list view.

The ConfigPage should only define an interface. For example it could contain methods like icon() (to get the icon for the list view), title(), read(), write() or similar. For each config page you are going to use, you should subclass ConfigPage and create concrete implementations, like FontConfigPage, ColorConfigPage and so on. Only these subclasses should know what settings they contain and what widgets to use to edit those settings.

Of course you will need some class to store settings that you can pass to every ConfigPage, for example QSettings.

This way you can easily reuse ConfigDialog in other places, or control the number of config pages depending on the current user, or have two versions of config dialog: "beginner" mode and "expert" mode, or... And all this you could achieve only by changing the list of pages displayed by the same ConfigDialog class.