PDA

View Full Version : Smart way to enable/disable Controls



sp3x
19th April 2016, 08:12
Hi,

whats the smartest way to enable or disable controls (control groups) in Qt?
I want to use something like an ACL (Access Controll List) in combination with QStateMachine to realize this.
Or is there a way to directly connect an ACL to controls? I.e. if a signal is emited like signalUserRoleChanged that I can connect this signal to a ControlGroup and this control group has a property with roles allowed to access this control group (Whitelist) and if the new role matches the whitelist so the controls should be enabled otherwise the controls should be disabled.

Aktually Iam using the verry messy method like this:

if(member()->isAdmin()) {
m_ui->actionUserManager->setEnabled(true);
m_ui->actionModuleControl->setEnabled(true);
m_ui->actionProgramControl->setEnabled(true);
m_ui->actionReportControl->setEnabled(true);
} else {
m_ui->actionUserManager->setEnabled(false);
m_ui->actionModuleControl->setEnabled(false);
m_ui->actionProgramControl->setEnabled(false);
m_ui->actionReportControl->setEnabled(false);
}

Regards

anda_skoa
19th April 2016, 09:48
If you change state in your state machine when you can use the state's assignProperty mechanism to change the enabled property.

If not, you could attach role information on each widget and then, at a central place, walk through the widgets and set enable/disable depending on the current role and the attached data.

Cheers,
_