PDA

View Full Version : Qdialog as a child widget



dave
13th November 2006, 14:28
hi

By default QDialog are created as a top level windows of the application. I have a QDialog that I want to make a child of a specific widget in my app so it will center on the widget. I passed my widget pointer as a parent to the QDialog , but it apears to do nothing.

How can I make QDialog as a child of a widget?

Thanks
Dave

sunil.thaha
13th November 2006, 14:48
Could you show the code ?

A wild guess ??

You might be creating the Dialog on the stack and called show or
You would have forgotted to call show or exec on the new Dialog

wysota
13th November 2006, 14:52
How can I make QDialog as a child of a widget?

If you mean a widget which is a child widget of some other widget (meaning it is not a top-level widget), then it doesn't make much sense to do so. If you wish to centre your dialog over some child widget, then simply fetch its coordinates, map them to global and position your dialog manually.

dave
13th November 2006, 15:03
....
unsigned int quality, width;
qualityWidget jpgQuality(this);
if (jpgQuality.exec() == QDialog::Rejected) return;
jpgQuality.results(quality, width);
....

this is the code. It is called from a window widget. the widget itself is a child of a qworkspace, which is a child of a qmainwindow.
qualityWidget is a inherited class of qdialog. the this pointer is passed straight to the qdialog constructor.

this is the declaration:

class qualityWidget : public QDialog
{
Q_OBJECT
....
public:
qualityWidget(QWidget* parent = 0);
~qualityWidget() {}
....


and this the definition:

qualityWidget::qualityWidget(QWidget* parent) : QDialog(parent)
{
....

jacek
13th November 2006, 15:04
it doesn't make much sense to do so.
Are you sure?

QDialog::QDialog ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
Constructs a dialog with parent parent.
A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent. It will also share the parent's taskbar entry.
The widget flags f are passed on to the QWidget constructor. If, for example, you don't want a What's This button in the title bar of the dialog, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint in f.
See also QWidget::setWindowFlags().

wysota
13th November 2006, 15:32
Are you sure?


QDialog::QDialog ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
Constructs a dialog with parent parent.
A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent. It will also share the parent's taskbar entry.
The widget flags f are passed on to the QWidget constructor. If, for example, you don't want a What's This button in the title bar of the dialog, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint in f.
See also QWidget::setWindowFlags().

The abstract you refer to (probably) means top-level widgets. I was referring to centering over child widgets of top-level widgets (for example centering over a dialogs button).

The author of the thread wishes to centre over a widget which is a child of QWorkspace (hence it's not a top-level widget) which seems to confirm my assumptions.

dave
13th November 2006, 15:33
wysota
I've a small program which create an lsystem 2d curves based on a literal string. I can save this then as images and I get a dialog which ask me to choose image quality. I'd like that dialog to block only the widget to which it belongs and not all the other widgets in the program.

jacek
I've seen this in the docs, but it doesn't apear to work for me:( .

jacek
13th November 2006, 16:31
The abstract you refer to (probably) means top-level widgets.
It isn't an abstract, but a direct quote from documentation.


I was referring to centering over child widgets of top-level widgets (for example centering over a dialogs button).
Me too and it worked like this in previous versions. It appears that this behavior was changed and the docs are inconsistent:

"Detailed Description" says:

A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself).

While QDialog constructor docs say:

A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent.

In other words: there's a bug in QDialog docs.

dave
13th November 2006, 17:30
So if this is the default behavior. is there any way for me to create a modal widget that will center on top of it's parent?
Using regular widget is no good because I need the dialog to run till it will return from the widget like the exec() function does.

Thanks

jacek
13th November 2006, 17:58
So if this is the default behavior. is there any way for me to create a modal widget that will center on top of it's parent?
You will have to move it there, but after the dialog was shown.

dave
13th November 2006, 22:02
But what I'm looking for is a behavior like Qt::WindowModal (http://doc.trolltech.com/4.2/qt.html#WindowModality-enum).
I want that only that parent widget which called the dialog will be blocked and all the other widgets will be free to move and pick and work with.

wysota
14th November 2006, 06:13
If you mean the children of QWorkspace then I doubt you can do this as these are not really windows, so they can't be blocked independently of each other - you'd have to block the whole window containing the workspace.

jacek
14th November 2006, 09:43
There was a similar issue with Qt3 and it was treated as a bug: http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=67471

So maybe you should ask the Trolls, if it should behave like it behaves now?