Reply
Thread Tools
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#1
I'm new to Qt and am trying to develop my first ever app in Qt ... I was trying to figure out whats the practical difference between QMessageBox, QDialogButtonBox, and QDialog (and also any other similar variants) .. ? The official documentation just lists all the technical aspects regarding these classes, but I was wondering, whats the difference between them ? For what purpose are each of these suited to ? Also, can anyone post any screenshots of any class implementations running on the N900 (like show separate pictures of onscreen QMessageBox, QDialogButtonBox, and QDialog running instances), so one can physically see what are the differences between them in terms of layout and capabilities ?
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#2
QDialog is the base dialog class, so it's very generic. QMessageBox is a subtype of QDialog aimed at providing informational dialogs, or ones offering a limited set of standard buttons (e.g. OK, Cancel). QDialogButtonBox is not a dialog at all, it's just a widget designed to hold a set of standard buttons. In fact, the QMessageBox will just be an implementation of a QDialog containing a QDialogButtonBox, and a text field.
 
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#3
Alright thanks, so if I had to add a Dialog with some buttons and stuff in it, like in this picture (taken from Erminig) .....



... I would have to have a QDialog, which contains all the controls I need ?
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#4
Originally Posted by ahmadka View Post
Alright thanks, so if I had to add a Dialog with some buttons and stuff in it, like in this picture (taken from Erminig) .....



... I would have to have a QDialog, which contains all the controls I need ?
Yes, a QDialog is the most flexible option, but the subclasses (like QMessageBox and QInputDialog) provide simple ways to implement standard dialogs. The Qt documentation provides screenshots of most of these - the Maemo implementation will be slightly different, but you should be able to get the basic idea of what each offers (and be able to match it to where you've seen the equivalent interfaces in Maemo) from there.
 
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#5
Alright thanks, but for the picture I've mentioned above, exactly which form of a Dialog is being used (e.g. QDialog, etc ..), and are those the ordinary Push Buttons that you see all over this Dialog ? ... I'm ask this because the first 3 buttons have a heading mentioned (e.g. 'Local Data Source'), and then a value mentioned next to it too (e.g. 'Built-in') in an orange color .. so this can't be an ordinary push button, can it ?
 
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#6
Ok I got another question ...

I'm trying to generate a Dialog box with a custom set of buttons and other controls, but one which looks similar to this:



That is, it pops up from the bottom of the screen in upwards direction, and does not occupy the entire screen (so that you can click outside the popup to hide it away again) ...

However, when I use the following code ...

Code:
QPushButton *b1 = new QPushButton(tr("Yes"));
    QPushButton *b2 = new QPushButton(tr("No"));

    b1->setDefault(true);
    b2->setAutoDefault(false);
    QDialogButtonBox * xx = new QDialogButtonBox(Qt::Vertical);
    xx->addButton(b1,QDialogButtonBox::YesRole);
    xx->addButton(b2,QDialogButtonBox::NoRole);
    xx->setWindowTitle(tr("Testing"));
    xx->setCenterButtons(true);
    xx->show();
... I get the following type of popup:



How can I make it like the first one, such that it doesnt occupy the entire screen, and also 'pops up' from the bottom of the screen ?
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#7
Originally Posted by ahmadka View Post
Alright thanks, but for the picture I've mentioned above, exactly which form of a Dialog is being used (e.g. QDialog, etc ..), and are those the ordinary Push Buttons that you see all over this Dialog ? ... I'm ask this because the first 3 buttons have a heading mentioned (e.g. 'Local Data Source'), and then a value mentioned next to it too (e.g. 'Built-in') in an orange color .. so this can't be an ordinary push button, can it ?
Assuming that's actually using Qt, it's almost certainly a plain QDialog. The buttons are a combination of QPushButton and QMaemo5ValueButton (see http://doc.qt.nokia.com/qt-maemo-4.6...luebutton.html).
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#8
Originally Posted by ahmadka View Post
Ok I got another question ...

I'm trying to generate a Dialog box with a custom set of buttons and other controls, but one which looks similar to this:



That is, it pops up from the bottom of the screen in upwards direction, and does not occupy the entire screen (so that you can click outside the popup to hide it away again) ...

However, when I use the following code ...

Code:
QPushButton *b1 = new QPushButton(tr("Yes"));
    QPushButton *b2 = new QPushButton(tr("No"));

    b1->setDefault(true);
    b2->setAutoDefault(false);
    QDialogButtonBox * xx = new QDialogButtonBox(Qt::Vertical);
    xx->addButton(b1,QDialogButtonBox::YesRole);
    xx->addButton(b2,QDialogButtonBox::NoRole);
    xx->setWindowTitle(tr("Testing"));
    xx->setCenterButtons(true);
    xx->show();
... I get the following type of popup:



How can I make it like the first one, such that it doesnt occupy the entire screen, and also 'pops up' from the bottom of the screen ?
You don't appear to have a QDialog at all there, just a QDialogButtonBox. As there's no overall dialog window, or layout manager, then I'm not surprised it looks odd. I'd recommend adding a top-level QDialog, and probably a QHBoxLayout as well (thatt may not be needed for a single widget though).
 
Posts: 341 | Thanked: 57 times | Joined on Nov 2009
#9
Forgive me, I'm such a n00b at this right now .. I tried using QDialog as well, but I couldn't figure out what method does it have to add buttons and stuff to it .. With QDialogButtonBox, there's an addButton method which can be used to add buttons to QDialogButtonBox ... How do I add controls to a QDialog ... ?

Also, as far as I can tell, QDialog is normally not directly used itself as well .. i.e., it functions just as a base class, and is mutated into other dialog forms such as QFileDialog, etc ... I'm saying this because when I try to search for example codes for QDialog, I always find codes for other such dialog forms, and not for QDialog itself ...
 
FBergeron's Avatar
Posts: 81 | Thanked: 62 times | Joined on Aug 2009 @ Nagoya, Japan
#10
I would suggest to look at the code of an existing application to learn how to use the Qt widgets.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 21:31.