Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] Custom dialog
QtWS25 Last Chance

[solved] Custom dialog

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jduran
    wrote on last edited by
    #1

    Hello all,

    I would like to create my own dialog class in QtQuick2. From which Quick element I could create it? Should I create it from scratch?

    Joaquim Duran

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Hello,

      well i would go ahead and create a new Window in for example myCustomDialog.qml. You can design the Window for your purposes. From you main QML you just create it as a new component and show it.
      @var component = Qt.createComponent("myCustomDialog.qml");
      dialog = component.createObject(root);
      dialog.show();@
      I would add some signals to your dialog, for example yes, no, whateveryouwant,... and then catch the emit of them with dialog.onYes, ... .

      Havn't tested it out but it should work :)

      For futher information:
      "Window":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick-window2-window.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jduran
        wrote on last edited by
        #3

        Looking in the source code of Qt, I've created this example:

        @
        import QtQuick 2.0
        import QtQuick.Dialogs 1.1
        import QtQuick.Controls 1.1
        import QtQuick.Layouts 1.1

        Rectangle {

        AbstractMessageDialog {
            id: dialog
            title: "Error message"
        
            ColumnLayout {
                anchors.fill: parent
        
                Text {
                    text: "Text of sample"
                }
        
                Button {
                    text: "close"
                    onClicked: {
                        dialog.close();
                    }
                }
            }
        }
        
        Button {
            text: "Show dialog"
            onClicked: dialog.open();  // Same as dialog.visible = true;
        }
        

        }
        @

        In the header file of AbstractMessageDialog, it is commented that the file is not part of Qt interface and that it could could be removed.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jduran
          wrote on last edited by
          #4

          And another sample, based on window:

          @
          import QtQuick 2.0
          import QtQuick.Controls 1.1
          import QtQuick.Layouts 1.1
          import QtQuick.Window 2.0

          Rectangle {
          width: 400
          height: 400

          Window {
              id: win_dialog
          
              flags: Qt.Dialog
              title: "Error message"
              modality: Qt.ApplicationModal
          
              ColumnLayout {
                  anchors.fill: parent
          
                  Text {
                      text: "Text of sample"
                  }
          
                  Button {
                      text: "close"
                      onClicked: {
                          win_dialog.visible = false;
                      }
                  }
              }
          
              visible: false
          }
          
          Button {
              text: "Show dialog"
              onClicked: win_dialog.visible = true;
          }
          

          }
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved