Results 1 to 6 of 6

Thread: How to make Dialog fit it's contents?

  1. #1
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to make Dialog fit it's contents?

    I have something like this:

    Qt Code:
    1. Dialog {
    2. id: dialog
    3. title: qsTr("Choose someText")
    4. standardButtons: StandardButton.Ok | StandardButton.Cancel
    5.  
    6. Row {
    7. id: row
    8. spacing: 5
    9. Label {text: qsTr("this is someText:");anchors.verticalCenter: tf.verticalCenter}
    10. TextField {
    11. id:tf
    12. text: someText
    13. }
    14. Label {text: "text2";anchors.verticalCenter: tf.verticalCenter}
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    But no matter what (changing spacing, commenting out labels), Dialog width always stays at 225 cutting part from leftmost label. In docs it said it should fit the content of it's content item but it doesn't! How to solve this? I don't want to recreate dialog with all of it's buttons and signals using window.
    P.S. sort of unrelated question: is there a way to wait until dialog is closed? For example if I want to use value retrieved from dialoge in signal, I want to .open() dialog and wait until it closes to send signal. connecting to onAccepted() won't work because I don't want to send this signal every time this dialog closes, only after I open it from specific place.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make Dialog fit it's contents?

    Have you tried using the width and height of "row" or its implicit height/width?

    I am not sure what you mean with "wait". Do you mean a modal dialog, i.e. one that blocks input to the parent window while it is open?
    If so, see the modality property.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to make Dialog fit it's contents?

    Quote Originally Posted by anda_skoa View Post
    Have you tried using the width and height of "row" or its implicit height/width?
    How? In docs it says:
    Note: do not attempt to bind the width or height of the dialog to the width or height of its content, because Dialog already tries to size itself to the content. If your goal is to change or eliminate the margins, you must override contentItem. If your goal is simply to show a window (whether modal or not), and your platform supports it, it is simpler to use Window instead.
    I am not sure what you mean with "wait". Do you mean a modal dialog, i.e. one that blocks input to the parent window while it is open?
    If so, see the modality property.
    I mean that if I write somewhere {dialog.open(), sendSignal(dialog.text)} it won't wait until dialog is closed to send signal (or do whatever action I write there). It will emit sendSignal right after dialog opens. And I can't (don't want to) add this to onAccpeted or whatever signal of dialog because I intend to use this dialog in many cases and I don't need to emit sendSignal every time I use this dialog. I know that in C++ you could do something like res = dialog.exec(), but I haven't found any alternatives for qml/js.
    Last edited by flashmozzg; 10th May 2015 at 23:24.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make Dialog fit it's contents?

    Quote Originally Posted by flashmozzg View Post
    How? In docs it says:
    I just tried this and it creates a dialog that can't be shrunk below its content's size
    Qt Code:
    1. import QtQuick 2.1
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Dialogs 1.2
    4.  
    5. Dialog {
    6. id: dialog
    7. title: qsTr("Choose someText")
    8. standardButtons: StandardButton.Ok | StandardButton.Cancel
    9.  
    10. Row {
    11. id: row
    12. spacing: 5
    13. Label {text: qsTr("this is someText:");anchors.verticalCenter: tf.verticalCenter}
    14. TextField {
    15. id:tf
    16. text: "foo"
    17. }
    18. Label {text: "text2";anchors.verticalCenter: tf.verticalCenter}
    19. }
    20.  
    21. Component.onCompleted: open()
    22. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by flashmozzg View Post
    And I can't (don't want to) add this to onAccpeted or whatever signal of dialog because I intend to use this dialog in many cases and I don't need to emit sendSignal every time I use this dialog.
    Using the same dialog type does not imply using the same instance.
    Any specific reason you want to use the same instance of the dialog?

    Cheers,
    _

  5. #5
    Join Date
    Feb 2015
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to make Dialog fit it's contents?

    Quote Originally Posted by anda_skoa View Post
    I just tried this and it creates a dialog that can't be shrunk below its content's size
    [/code]
    I just tried compiling my app on my laptop - and there it creates dialog of appropriate size! But not on my PC! See: http://i.imgur.com/0vguCtZ.png
    The only difference I can think of (same OS and settings) is monitor resolution.
    Even stranger is that when I compile and run my app on my Android device it has this problem too! I'll try to deploy my app to my smartphone from laptop and see if the problem persists.
    Edit: tried on emu from laptop - same problem there.
    Using the same dialog type does not imply using the same instance.
    Any specific reason you want to use the same instance of the dialog?
    _
    Hm, using may loaders instead of many dialogs? That might work! Thanks!
    Last edited by flashmozzg; 11th May 2015 at 14:18.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to make Dialog fit it's contents?

    Quote Originally Posted by flashmozzg View Post
    Hm, using may loaders instead of many dialogs? That might work! Thanks!
    Another option is to have your own open() function that takes a reference to a "receiver" object and in onAccepted to just call a function on that object.
    I think you can even pass a function as an argument, i.e. basically a callback.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 19th February 2013, 23:23
  2. Replies: 0
    Last Post: 8th June 2012, 13:27
  3. Replies: 2
    Last Post: 30th July 2010, 16:44
  4. how to make these contents work??
    By srohit24 in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2009, 14:02
  5. How to make Search Dialog as it is used by MAC O.S
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2008, 09:46

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.