[Qt-interest] any planned improvement to QMessageBox interfaces?

Malyushytsky, Alex alex at wai.com
Fri Nov 6 02:56:07 CET 2009


First I would like to comment that "Erase the Hard Disk" does not fall in "use-verbs-as-labels" concept.
It is more like "use-sentences-as-labels", in this case I would prefer yes/no.

Anyway, if you need to be able to specify the labels, what prevents you from writing your static function(s) which do it.
(It probably not worth to derive your class from QMessageBox just to add static functions, so you might keep them global)


Assume you had the following code:
int ret = QMessageBox::critical( parent, title, text ) ;

Create  static functions, declared as:

QMessageBox::StandardButton criticalMessageBox ( QWidget * parent, const QString & title, const QString & text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton,
QStringList* buttonLabels = NULL )

Or for convenience you can provide2 functions:

QMessageBox::StandardButton criticalMessageBox ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok,
QStringList* buttonLabels = NULL );



Replace the text "QMessageBox::critical" on "criticalMessageBox" in all files.
(Make sure you include header with criticalMessageBox declarations)


You should have
int ret = criticalMessageBox ( parent, title, text ) ;

Now everything should work the same way it was before.

When you ready to replace the text on the buttons, add the code :
QStringList lst;
lst << qApp->tr("Erase the Hard Disk")
    << qApp->tr("Don't erase the Hard Disk");

int ret = criticalMessageBox ( parent, title, text, & lst ) ;

Possible implementation of your static function:

QMessageBox::StandardButton criticalMessageBox ( QWidget * parent, const QString & title, const QString & text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton,
QStringList* buttonLabels = NULL )
{
  QMessageBox::StandardButton ret;
  if(buttonLabels)
  {
    ret = QMessageBox::critical( parent, title, text, buttons, defaultButton);
  }
  else
  {

      QMessageBox messageBox(parent);
      messageBox->button(QMessageBox::Yes)->setText("Erase the Hard Disk");
     messageBox->button(QMessageBox::No)->setText("Don't erase the Hard Disk");
         .... // set title, text, buttons

     ret =  messageBox->exec();
}

That is it.

Regards,
  Alex





-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Ross Bencina
Sent: Wednesday, November 04, 2009 7:24 PM
To: Qt-Interest
Subject: [Qt-interest] any planned improvement to QMessageBox interfaces?

Hi

I'm planning to improve my app by replacing the standard Yes/No/Cancel
buttons in all my QMessageBox calls with context specific verbs as per
current user interface guidelines. eg
http://www.usabilitypost.com/2008/08/30/usability-tip-use-verbs-as-labels-on-buttons/
http://msdn.microsoft.com/en-us/library/aa511268.aspx#respondMainInstruction

I know I can do this with Qt4.5 by explicitly instantiating a QMessageBox
and then using something like:

QMessageBox messageBox(...);
messageBox->button(QMessageBox::Yes)->setText("Erase the Hard Disk");
messageBox->button(QMessageBox::No)->setText("Don't erase the Hard Disk");
if( messageBox->exec() == QMessageBox::Yes ){
    eraseTheHardDisk();
}

But at the moment I'm using the (very convenient) static functions
(QMessageBox::question() et al) so its quite a bit of work to rework all my
code to use non-static message boxes.

Before I decide how to proceed I would like to know if there are plans to
support customising message box button texts via the the static message box
functions in Qt 4.6 or in the future?

Perhaps there is a cleaner way to do it, but I'm imagining something like:

if( QMessageBox::question( 0, "MyApp", "Do you want to erase the Hard
Disk?",
        QMessageBox::NamedStandardButtonList()
                << QMessageBox::NamedStandardButton( QMessageBox::Yes,
"Erase the Hard Disk" )
                << QMessageBox::NamedStandardButton( QMessageBox::No, "Don't
erase the Hard Disk" ),
        /* default= */ QMessageBox::No ) == QMessageBox::Yes ){

    eraseTheHardDisk();
}

Is this planned or should I rewrite to the first way?

Thanks!

Ross.



_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list