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

Jesús Fernández jsfdez at gmail.com
Mon Mar 2 12:00:46 CET 2009


More information, the value is read from the model but when I change the
rgb() function is not called and the model is not updated.

The code in the MainWindow is:

> { // landmarkWidgetMapper setup
>
> VWLandmarkTableModel *m=vwLandmarkTableModel;
>
> QDataWidgetMapper *w=landmarkWidgetMapper;
>
>  w->setSubmitPolicy(w->AutoSubmit);
>
> w->setModel(m);
>
> w->addMapping(penColorToolButton, m->PenColorColumn);
>
> w->addMapping(brushColorToolButton, m->BrushColorColumn);
>
> }
>


On Mon, Mar 2, 2009 at 11:01 AM, Jesús Fernández <jsfdez at gmail.com> wrote:

> 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/d6c4e110/attachment.html 


More information about the Qt-interest-old mailing list