Q_OBJECT
public:
const QAction *action
() const { return _action;
} void setAction
(QAction *a
){ initAction
(a
);
} private:
QPointer<QAction> _action;
protected slots:
void updateAction();
};
if(_action) initAction(act);
}
void QActionCheckBox
::initAction(QAction *a
){ _action = a;
if(_action){
connect(_action, SIGNAL(changed()), this, SLOT(updateAction()));
connect(this, SIGNAL(stateChanged(bool)), _action, SLOT(setChecked(bool)));
updateAction();
}
}
void QActionCheckBox::updateAction(){
if(!action) return;
setEnabled(_action->isEnabled());
setText(_action->text());
if(_action->isCheckable()) setChecked(_action->isChecked());
}
class QActionCheckBox : public QCheckBox {
Q_OBJECT
public:
QActionCheckBox(QAction *act, QWidget *p = 0);
const QAction *action() const { return _action; }
void setAction(QAction *a){ initAction(a); }
private:
QPointer<QAction> _action;
void initAction(QAction *a);
protected slots:
void updateAction();
};
QActionCheckBox::QActionCheckBox(QAction *act, QWidget *p) : QCheckBox(p){
if(_action) initAction(act);
}
void QActionCheckBox::initAction(QAction *a){
_action = a;
if(_action){
connect(_action, SIGNAL(changed()), this, SLOT(updateAction()));
connect(this, SIGNAL(stateChanged(bool)), _action, SLOT(setChecked(bool)));
updateAction();
}
}
void QActionCheckBox::updateAction(){
if(!action) return;
setEnabled(_action->isEnabled());
setText(_action->text());
if(_action->isCheckable()) setChecked(_action->isChecked());
}
To copy to clipboard, switch view to plain text mode
Satisfied? You can make a designer plugin with this class and place this widget on a form. I haven't checked it but even if it contains errors, the idea is simple, so you'll be able to modify it.
Bookmarks