Hi,
thanks a lot for your helpful instructions! I first tried out the Qt-ish solution based on signals and slots as follows:
In the wizard page class I added a connect(...) statement:
VisualPropertiesPage
::VisualPropertiesPage(QWidget *parent
) : QWizardPage(parent),
ui(new Ui::VisualPropertiesPage) {
ui->setupUi(this);
[...]
GraphWizard *wiz = static_cast<GraphWizard*>(wizard());
connect(this, SIGNAL(lineColorSet(const QColor&)), wiz, SLOT(setLineColor(const QColor&)));
[...]
VisualPropertiesPage::VisualPropertiesPage(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::VisualPropertiesPage) {
ui->setupUi(this);
[...]
GraphWizard *wiz = static_cast<GraphWizard*>(wizard());
connect(this, SIGNAL(lineColorSet(const QColor&)), wiz, SLOT(setLineColor(const QColor&)));
[...]
To copy to clipboard, switch view to plain text mode
I defined a signal lineColorSet(QColor &color):
class VisualPropertiesPage : public QWizardPage {
Q_OBJECT
[...]
signals:
void lineColorSet
(const QColor &color
);
[...]
class VisualPropertiesPage : public QWizardPage {
Q_OBJECT
[...]
signals:
void lineColorSet(const QColor &color);
[...]
To copy to clipboard, switch view to plain text mode
Finally in the slot method on_lineColorBtn_clicked() I added an emit staetement:
void VisualPropertiesPage::on_lineColorBtn_clicked() {
ui->lineColorBtn->setPalette(pal);
QWizard *aWizard = wizard();
emit lineColorSet(color);
}
void VisualPropertiesPage::on_lineColorBtn_clicked() {
QColor color = QColorDialog::getColor(Qt::black, this, "Pick a color",
QColorDialog::DontUseNativeDialog);
QPalette pal;
pal.setColor(QPalette::Button, color);
ui->lineColorBtn->setPalette(pal);
QWizard *aWizard = wizard();
emit lineColorSet(color);
}
To copy to clipboard, switch view to plain text mode
In the QWizard subclass GraphWizard I defined a member
QColor mLineColor;
To copy to clipboard, switch view to plain text mode
and a slot to set that member:
public slots:
void setLineColor
(const QColor &color
);
public slots:
void setLineColor(const QColor &color);
To copy to clipboard, switch view to plain text mode
Now the signal slot mechanism should work. Much to my surprise this didn't work. The signal is emitted but the setLineColor(...) method in GraphWizard does not get called. I have no idea why. So I implemented the needed functionality in a somewhat similar way to your first proposal:
In the slot method on_lineColorBtn_clicked() instead of the emit statement I added this line:
QWizard *aWizard = wizard();
static_cast<GraphWizard*>(aWizard)->setLineColor(color);
QWizard *aWizard = wizard();
static_cast<GraphWizard*>(aWizard)->setLineColor(color);
To copy to clipboard, switch view to plain text mode
This way the color is passed to the wizard and can be accessed there in the accept() method.
While this now in principle works fine I'm still curious if there would be a possibility to implement this functionality somehow using the registerField(...)/field(...) mechanism. As already mentioned one normally would place a registerField(...) method in the ctor. of the wizard page. The method's signature looks as follows:
void registerField
(const QString &name,
QWidget *widget,
const char *property
= Q_NULLPTR,
const char *changedSignal = Q_NULLPTR)
void registerField(const QString &name, QWidget *widget, const char *property = Q_NULLPTR,
const char *changedSignal = Q_NULLPTR)
To copy to clipboard, switch view to plain text mode
So my idea now is to pass the palette object through the field. So my call to registerField should look somewhat similar to this:
registerField("lineColorPalette", ui->lineColorBtn, ui->lineColorBtn->palette(),
ui->lineColorBtn-><SomeSignal>);
registerField("lineColorPalette", ui->lineColorBtn, ui->lineColorBtn->palette(),
ui->lineColorBtn-><SomeSignal>);
To copy to clipboard, switch view to plain text mode
Any ideas?
Bookmarks