This class implements a dialog containing several preference pages.
To append your own page you just have to take note of these points:
- Each preference page can be created by the Qt Designer selecting the "Widget" item in the project dialog.
- To save or load the widgets' settings automatically (e.g. combo boxes, line edits, check boxes, ...) you can make use of the classes inherited from PrefWidget such as: PrefSpinBox, PrefLineEdit, PrefComboBox, PrefListBox, PrefCheckBox, PrefRadioButton and PrefSlider. If you have compiled and installed the library under src/Tools/plugins/widgets to QTDIR/plugins/designer you should see the new category "Preferences". Moreover you have to make sure to have specified the "prefEntry" and "prefPath" properties for each preference widget you have used inside your form in Qt Designer.
- For each widget inside your page - you want to save or load - you have to call <objectname>->onSave() or <objectname>->onRestore(). The best way to this is either to define the protected slots saveSettings() and loadSettings() in your form and overwrite them in a subclass or define these slots in this subclass directly.
See the example below for more details:
{
public:
MyPrefPage(
QWidget* parent = 0,
const char* name = 0, WFlags fl = 0 )
{
myLineEdit->setProperty( "prefEntry", "lineedit" );
myLineEdit->setProperty( "prefPath", "GroupName" );
myCheckBox->setProperty( "prefEntry", "checkbox" );
myCheckBox->setProperty( "prefPath", "GroupName" );
...
}
};
In the derived class you just have to implement the methods saveSettings() and loadSettings() in the following way:.
class MyPrefPageImp : public MyPrefPage
{
public:
MyPrefPageImp(
QWidget* parent = 0,
const char* name = 0, WFlags fl = 0 )
{
}
protected Q_SLOTS:
void saveSettings()
{
myLineEdit->onSave();
myCheckBox->onSave();
}
void loadSettings();
{
myLineEdit->onRestore();
myCheckBox->onRestore();
}
};
- Now you have to make the widget factory to know your class by adding the line new PrefPageProducer<MyPrefPageImp> (QT_TR_NOOP("My category"));
- See also
- PrefWidget
- Author
- Werner Mayer, Jürgen Riegel