So you connect to a local slot and that one calls submit(), should work as well.
Is the slot being invoked?
it definitely works in C++. I have a color editing widget and connect its signal to the datawidgetmapper's submit() slot and whenever I change color, the model is update accordingly.
#ifndef COLOREDITOR_H
#define COLOREDITOR_H
#include <QColor>
#include <QWidget>
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged
)
public:
explicit ColorEditor
(QWidget *parent
= 0);
signals:
void colorChanged
(const QColor &color
);
public slots:
void setColor
(const QColor &color
);
private:
private slots:
void onButtonClicked();
};
#endif // COLOREDITOR_H
#ifndef COLOREDITOR_H
#define COLOREDITOR_H
#include <QColor>
#include <QWidget>
class QLineEdit;
class ColorEditor : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
explicit ColorEditor(QWidget *parent = 0);
QColor color() const;
signals:
void colorChanged(const QColor &color);
public slots:
void setColor(const QColor &color);
private:
QColor m_color;
QLineEdit *m_lineEdit;
private slots:
void onButtonClicked();
};
#endif // COLOREDITOR_H
To copy to clipboard, switch view to plain text mode
#include "coloreditor.h"
#include <QColorDialog>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
ColorEditor
::ColorEditor(QWidget *parent
){
hbox->addWidget(m_lineEdit);
hbox->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QColor ColorEditor
::color() const {
return m_color;
}
void ColorEditor
::setColor(const QColor &color
) {
if (color == m_color) {
return;
}
m_color = color;
m_lineEdit->setText(m_color.name());
emit colorChanged(color);
}
void ColorEditor::onButtonClicked()
{
if (!color.isValid()) {
return;
}
setColor(color);
}
#include "coloreditor.h"
#include <QColorDialog>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
ColorEditor::ColorEditor(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *hbox = new QHBoxLayout(this);
m_lineEdit = new QLineEdit(this);
hbox->addWidget(m_lineEdit);
QPushButton *button = new QPushButton("...", this);
hbox->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QColor ColorEditor::color() const
{
return m_color;
}
void ColorEditor::setColor(const QColor &color)
{
if (color == m_color) {
return;
}
m_color = color;
m_lineEdit->setText(m_color.name());
emit colorChanged(color);
}
void ColorEditor::onButtonClicked()
{
const QColor color = QColorDialog::getColor(m_color, this);
if (!color.isValid()) {
return;
}
setColor(color);
}
To copy to clipboard, switch view to plain text mode
ui->tableView->setModel(model);
mapper->setModel(model);
mapper->addMapping(ui->name, 0);
mapper->addMapping(ui->color, 1, "color");
mapper->toFirst();
connect(ui
->color,
SIGNAL(colorChanged
(QColor)), mapper,
SLOT(submit
()));
ui->tableView->setModel(model);
QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(ui->name, 0);
mapper->addMapping(ui->color, 1, "color");
mapper->toFirst();
connect(ui->color, SIGNAL(colorChanged(QColor)), mapper, SLOT(submit()));
To copy to clipboard, switch view to plain text mode
Cheers,
_
Bookmarks