[Qt-interest] The QDataWidgetMapper does not update the value when changed

Jesús Fernández jsfdez at gmail.com
Mon Mar 2 11:01:53 CET 2009


Hi,

I have a QDataWidgetMapper wich is connected to a model and this
QToolButton:

(Header)

> class ColorToolButton : public QToolButton
>
> {
>
> Q_OBJECT
>
> Q_PROPERTY(qlonglong rgb READ rgb WRITE setRgb)
>
> public:
>
> ColorToolButton(QWidget *parent=0);
>
>  qlonglong rgb() const;
>
> public slots:
>
> void setRgb(qlonglong value);
>
> void showColorDialog();
>
> void clearColor();
>
> signals:
>
> void valueChanged(qlonglong newValue);
>
> private:
>
> qlonglong m_rgb;
>
> };
>

Source:

> #include "colortoolbutton.h"
>
> #include <QtGui>
>
> ColorToolButton::ColorToolButton(QWidget *parent)
>
> : QToolButton(parent)
>
> {
>
> connect(this, SIGNAL(clicked()), SLOT(showColorDialog()));
>
> }
>
> qlonglong ColorToolButton::rgb() const
>
> {
>
> return m_rgb;
>
> }
>
> void ColorToolButton::setRgb(qlonglong value)
>
> {
>
> m_rgb=value;
>
> QColor color(value);
>
> QPixmap pixmap(16, 16);
>
> QPainter painter(&pixmap);
>
> QRect rect=pixmap.rect();
>
>  painter.setRenderHint(painter.Antialiasing);
>
> painter.eraseRect(rect);
>
> painter.setPen(Qt::black);
>
> if(value!=0) painter.setBrush(QBrush(color, Qt::SolidPattern));
>
> else {
>
> painter.drawLine(rect.topLeft(), rect.bottomRight());
>
> painter.drawLine(rect.topRight(), rect.bottomLeft());
>
> }
>
> painter.drawRect(rect);
>
> setIcon(QIcon(pixmap));
>
> }
>
> void ColorToolButton::showColorDialog()
>
> {
>
> QRgb defColor=m_rgb;
>
> bool ok;
>
> QRgb color=QColorDialog::getRgba(defColor, &ok, this);
>
>  if(!ok) return;
>
> else if(color!=m_rgb) {
>
> emit valueChanged(color);
>
> setRgb(color);
>
> }
>
> }
>
> void ColorToolButton::clearColor()
>
> { setRgb(0); }
>

What could be the problem? Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090302/3f47efbf/attachment.html 


More information about the Qt-interest-old mailing list