SNC
SNC

Reputation: 59

qt - allow user to press only one button with a dialog opened

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.

Upvotes: 0

Views: 460

Answers (1)

Jablonski
Jablonski

Reputation: 18504

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.

Upvotes: 1

Related Questions