Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable sounds played by Qt QMessageBox?

Tags:

windows

qt

I am working on a Windows application using Qt 4.8 that uses

QMessageBox::information
QMessageBox::warning
...

When any of thes functions is called, windows plays by default a sound. My customers are annoyed of this and want to disable this permanently without changing windows settings.

How can I get rid if this sound?

I found that it is called from

void QAccessible::updateAccessibility()

But I do not so far see a way to disable it.

like image 882
RED SOFT ADAIR Avatar asked Apr 17 '13 20:04

RED SOFT ADAIR


1 Answers

If you use a different QMessageBox, QMessageBox::about, or make your own instance of QMessageBox and set the iconPixmap and everything yourself, you shouldn't get the beeping noise.

QMessageBox::warning(0, "Test", "test"); // Plays alert

QMessageBox::about(0, "Test", "test"); // No sound, but no icon either

QMessageBox msgBox;
msgBox.setParent(0);
msgBox.setWindowTitle("Test");
msgBox.setText("test");
if(false)
{
    msgBox.setIcon(QMessageBox::Warning);// makes sound
}
else
{
    QPixmap p;
    p.load("warning.png");
    msgBox.setIconPixmap(p);// no sound, but with icon
}
msgBox.exec();

Otherwise, to disable the warning sound, you probably will need a global event filter on your app to catch any event/message from QAccessibility with the role of QAccessible::AlertMessage.

Hope that helps.

like image 136
phyatt Avatar answered Oct 15 '22 22:10

phyatt