0

I'm using QT and I have done a full screen application with some buttons and controls. Sometimes when an error pops up a dialog is showed and stay opened (stay on top).

I would like to have a button inside the application screen that could be pressed also when this dialog is opened, but all the other controls/buttons should be not usable.

I thought about something like a transparent custom widget with a special form over the application without covering the "special" button but I really don't know if it's so simply.

SNC
  • 59
  • 2
  • 15

1 Answers1

1

Create one special button and set object name to this button:

pushButton->setObjectName("special");

Find all your buttons:

QList<QPushButton*> allButtons = this->findChildren<QPushButton*>();
for(int i = 0; i < allButtons.size(); ++i)
{
    if(allButtons.at(i)->objectName() != "special")
        allButtons.at(i)->setEnable(false);
}
allButtons.clear();

Now all not special buttons are disabled, to enable - do the same thing.

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • This won't scale well as elements are added. – Nicolas Holthaus Sep 26 '14 at 11:12
  • @NicolasHolthaus Are you talking about dynamic added pushButtons? – Jablonski Sep 26 '14 at 11:16
  • He only wants one control enabled, and all others disabled, meaning any time he added a control he'd have to add a line of code to the 'disable All' function or whatever, which goes against the open/closed principle IMO. I think there is a more scalable approach. – Nicolas Holthaus Sep 26 '14 at 11:22
  • 1
    @NicolasHolthaus I understood you and totally rewrited my answer, Now it works with any buttons and does not require new lines of code. – Jablonski Sep 26 '14 at 11:31
  • Agreed, much improved – Nicolas Holthaus Sep 26 '14 at 12:19
  • Thank you guys but it works only for buttons, in my application I have also other type of controls like list, edit lines etc. I would like to have a "final solution" for all controls also if added in the future. – SNC Sep 29 '14 at 07:07
  • @SNC Do you want disable every widget instead of one specific? If so, then I will update my answer and solve your problem. Tell me it please. – Jablonski Sep 29 '14 at 16:45