maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ?? (https://talk.maemo.org/showthread.php?t=55813)

ahmadka 2010-06-10 19:43

What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
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 ?

Rob1n 2010-06-10 19:50

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
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.

ahmadka 2010-06-11 09:59

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Alright thanks, so if I had to add a Dialog with some buttons and stuff in it, like in this picture (taken from Erminig) .....

http://img809.imageshack.us/img809/6369/erminig.png

... I would have to have a QDialog, which contains all the controls I need ?

Rob1n 2010-06-11 10:13

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by ahmadka (Post 710149)
Alright thanks, so if I had to add a Dialog with some buttons and stuff in it, like in this picture (taken from Erminig) .....

http://img809.imageshack.us/img809/6369/erminig.png

... 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.

ahmadka 2010-06-11 11:02

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
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 ?

ahmadka 2010-06-11 11:57

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
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:

http://img39.imageshack.us/img39/2501/36179072.png

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:

http://img217.imageshack.us/img217/4571/38304045.png

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 ?

Rob1n 2010-06-11 12:56

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by ahmadka (Post 710250)
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).

Rob1n 2010-06-11 12:58

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by ahmadka (Post 710309)
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:

http://img39.imageshack.us/img39/2501/36179072.png

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:

http://img217.imageshack.us/img217/4571/38304045.png

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).

ahmadka 2010-06-11 13:42

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
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 2010-06-11 13:57

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
I would suggest to look at the code of an existing application to learn how to use the Qt widgets.

Rob1n 2010-06-11 14:24

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by ahmadka (Post 710455)
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 ... ?

You generally don't directly. You'll want to create a layout (or a set of nested layouts) to... erm... layout... the design of your dialogue. You then use addWidget (and addLayout) to build them up. Finally you can use setLayout to add the top-level layout to your dialog.

I'd suggest reading the documentation on this - http://doc.qt.nokia.com/qt-maemo-4.6...d-layouts.html and http://doc.qt.nokia.com/qt-maemo-4.6/layout.html should cover how widgets and layouts interact (a QDialog is really just another widget).

Venemo 2010-06-11 15:06

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Hey,

Rob1n said all the good things and stuff, I just would like to add one more tip:

Basically, all of these classes have great static methods that should ease your life.

pelago 2010-06-11 15:31

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
You might want to look into getting a book about Qt such as one of those listed at http://qt.nokia.com/developer/books/ (can anyone make some specific recommendations?)

fatalsaint 2010-06-11 15:35

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
1 Attachment(s)
Quick example, basically ripped it from here and modified it to do what you're asking (simplistically, you'll still need to figure out formatting). I only left comments in the areas that I changed since you can read his original tutorial/comments at the website.

Developed, screenshotted, and uploaded to a webserver all on my N900. I love this "phone" :D!

Code:

#I don't use PySide
from PyQt4 import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class MyMainWindow(QWidget):
        def __init__(self):
                QWidget.__init__(self, None)
 
                vbox = QVBoxLayout()
 
                b = QPushButton("Push me!")
                vbox.addWidget(b)
 
                self.connect(b, SIGNAL("clicked()"), self.buttonPushed)
 
                self.setLayout(vbox)
 
        def buttonPushed(self):
                d = QDialog(self)
 
                vbox = QVBoxLayout()
                #Add Layouts
                horizontalLayout = QHBoxLayout()
                horizontalLayout1 = QHBoxLayout()

                # Now create your buttons.
                b = QPushButton("Close window")
                c = QPushButton("Die")
                e = QPushButton("In Fires")
                f = QPushButton("With Chickens!")
 
                self.connect(b, SIGNAL("clicked()"), d.close)
 
                # Add buttons to your layouts, they'll show up in the order given.
                horizontalLayout1.addWidget(f)
                horizontalLayout1.addWidget(b)
                horizontalLayout.addWidget(c)
                horizontalLayout.addWidget(e)
 
                # Add layouts to your main Layout
                vbox.addLayout (horizontalLayout)
                vbox.addLayout (horizontalLayout1)
                d.setLayout(vbox)
 
                # Show the window!
                d.show()
 
if __name__ == '__main__':
        app = QApplication(sys.argv)
 
        w = MyMainWindow()
        w.show()
 
        app.exec_()
        sys.exit()


ahmadka 2010-06-11 20:43

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Alright thanks everyone for your support .. working like a charm now :)

One more question, how can I make the QDialog pop out from the sides, instead of from the bottom in an upward direction ?

aspidites 2010-06-11 20:51

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by ahmadka (Post 711181)
Alright thanks everyone for your support .. working like a charm now :)

One more question, how can I make the QDialog pop out from the sides, instead of from the bottom in an upward direction ?

Set the orientation attribute:
Code:

self.setAttribute(Qt.WA_Maemo5PortraitOrientation)
You will do this on the dialog's parent widget usually. Though it's possible to do this on the dialog itself, its weird to do so. It will change the orientation of the window, then once the dialog is closed, it will go back to its original orientation.

For more examples of orientation, how to use forms created with Qt Designer, or anything else, check out the source of maegym
Code is fairly clean, though I plan to refactor a few things.

ahmadka 2010-06-11 21:02

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Quote:

Originally Posted by aspidites (Post 711198)
If it has no parent, you can just set the orientation attribute:
Code:

self.setAttribute(Qt.WA_Maemo5PortraitOrientation)
If it belongs to another widget (has a parent), you will set this attribute on its parent.

For more examples of orientation, how to use forms created with Qt Designer, or anything else, check out the source of maegym
Code is fairly clean, though I plan to refactor a few things.

errr ... I think you misunderstood me .. I'm not talking about switching to Portrait mode or anything, or that how do I popup the QDialog properly while in portrait mode ...

I'm asking how can I make the QDialog pop out from the left side of the screen (or from the right side of the screen), instead of poping out from the bottom of the screen ?

Here is a picture to show what I mean:

http://img693.imageshack.us/img693/42/p1x.png

The bottom center arrow with a cross on it depicts the normal bottom --> up poping method .. how can I instead have vertical QDialogs that pop into view from either the left or right side of the screen ? Is this possible ?

aspidites 2010-06-11 21:38

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
My guess would be subclass QDialog and override the show method and or show event, using a QPropertyAnimation.

ahmadka 2010-06-11 22:57

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Yep, it seems to be more difficult than I thought ... Any code examples for doing such show () method re-implementations with different animations ?

ahmadka 2010-06-12 06:22

Re: What's the practical difference between QMessageBox, QDialogButtonBox, and QDialog ??
 
Any solutions ?


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

vBulletin® Version 3.8.8