Hi there,

I'm building a GUI in C++ on Linux using Qt 5.9. I want to implement a functionality for choosing a color as part of a wizard. What I have in mind is a solution somewhat similar to what I know from the color selection for syntactic items in C/C++ code in Eclipse CDT's preferences which looks like this:

Eclipse color chooser.PNG

I created a subclass of QWizardPage which contains (among other widgets) a QLabel which contains the text "Color:" followed by a QPushButton:

Qt widgets.PNG

With this code placed in the wizard page's ctor. I implement the color
chooser functionality:

Qt Code:
  1. VisualPropertiesPage::VisualPropertiesPage(QWidget *parent) :
  2. QWizardPage(parent),
  3. ui(new Ui::VisualPropertiesPage) {
  4.  
  5. ui->setupUi(this);
  6.  
  7.  
  8. // Initialize the color chooser.
  9. QPalette pal;
  10. pal.setColor(QPalette::Button, Qt::black);
  11. pal.setColor(QPalette::ButtonText, Qt::white);
  12. ui->lineColorBtn->setPalette(pal);
  13.  
  14. [...]
To copy to clipboard, switch view to plain text mode 

To execute the QColorDialog I implement a slot method as follows:


Qt Code:
  1. void VisualPropertiesPage::on_lineColorBtn_clicked() {
  2. QColor color = QColorDialog::getColor(Qt::black, this, "Pick a color",
  3. QColorDialog::DontUseNativeDialog);
  4. QPalette pal;
  5. pal.setColor(QPalette::Button, color);
  6. ui->lineColorBtn->setPalette(pal);
  7. }
To copy to clipboard, switch view to plain text mode 

This way I can easily select a color. My problem now is:

How can I access the choosen color in the wizard's accept() method?

I know that there is the method

registerField(cons QString &name, QWidget *widget, const char *property, const char *changedSignal)

but couldn't figure out yet, how to call it to gain access to the
button's color. I don't know how to specify the third and fourth parameter.

Or is there possibly a completely different (and easier) way to
configure a color value in a wizard?

Any hint is appreciated!