[Qt-interest] implement a simple parameter pane with variable changing underneath

Neil Girdhar mistersheik at gmail.com
Thu Apr 30 08:15:44 CEST 2009


Hi all,

I'm trying to implement a parameter pane with a whole bunch of controls for
parameters.  Sometimes the user interacts with the parameter pane, and then
any corresponding values in the program need to be changed.  Sometimes the
program progresses to a new state, and the UI needs to be updated.  This is
complicated by the fact that one parameter pane item (a QWidget) might point
to many values underneath.

I have included a snippet of my code that illustrates what I am trying to
do.  However, it's clear to me that there must be a better way to do this.

Also, how do I call valueChangedUnderneath for all child QWidgets in a
hierarchy?  Is there an easy way to use the custom event system to do this?

Thanks so much in advance!

Neil

ps I am using Qt4.4 and C++ 0x, but that shouldn't matter.

class ValueWriterDouble: public QDoubleSpinBox {
    Q_OBJECT

public:
    ValueWriterDouble(vector<double*> const& value): myValue(value) {
        QObject::connect(this, SIGNAL(valueChanged(double)), this,
SLOT(valueChanged(double)));
       }
    ~ValueWriterDouble() {}

public slots:
    void    valueChanged(double new_value) {
        for (auto it = myValue.begin(); it != myValue.end(); ++it)
            **it = new_value;
    }

    void    valueChangedUnderneath() {
        if (myValue.empty()) {
            CHECK(false);
            return;
        }
        bool consistent = true;
        double desired_value = *myValue.front();
        for (auto it = myValue.begin(); it != myValue.end(); ++it)
            if (*it != desired_value) {
                consistent = false;
                break;
            }
        if (!consistent) {
            // blank the widget text
        } else {
            // set the widget text and value to desired_value
            setValue(desired_value);  // this causes an unnecessary
valueChanged event
        }
    }

private:
    vector<double*>         myValue;
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090429/cb5b3f88/attachment.html 


More information about the Qt-interest-old mailing list