Results 1 to 13 of 13

Thread: Qdialog as a child widget

  1. #1
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qdialog as a child widget

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    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
    We can't solve problems by using the same kind of thinking we used when we created them

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qdialog as a child widget

    Quote Originally Posted by dave View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    Qt Code:
    1. ....
    2. unsigned int quality, width;
    3. qualityWidget jpgQuality(this);
    4. if (jpgQuality.exec() == QDialog::Rejected) return;
    5. jpgQuality.results(quality, width);
    6. ....
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. class qualityWidget : public QDialog
    2. {
    3. Q_OBJECT
    4. ....
    5. public:
    6. qualityWidget(QWidget* parent = 0);
    7. ~qualityWidget() {}
    8. ....
    To copy to clipboard, switch view to plain text mode 

    and this the definition:
    Qt Code:
    1. qualityWidget::qualityWidget(QWidget* parent) : QDialog(parent)
    2. {
    3. ....
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    Quote Originally Posted by wysota View Post
    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().

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qdialog as a child widget

    Quote Originally Posted by jacek View Post
    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.

  7. #7
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    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 .

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    Quote Originally Posted by wysota View Post
    The abstract you refer to (probably) means top-level widgets.
    It isn't an abstract, but a direct quote from documentation.

    Quote Originally Posted by wysota View Post
    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.

  9. #9
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    Quote Originally Posted by dave View Post
    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.

  11. #11
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    But what I'm looking for is a behavior like Qt::WindowModal.
    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.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qdialog as a child widget

    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qdialog as a child widget

    There was a similar issue with Qt3 and it was treated as a bug: http://www.trolltech.com/developer/t...entry&id=67471

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

Similar Threads

  1. how to find a child widget?
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2006, 11:30
  2. Replies: 1
    Last Post: 28th July 2006, 15:10
  3. minimize child widget
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2006, 13:02
  4. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 13:00
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.