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

Icon Dialog

Scheduled Pinned Locked Moved QML and Qt Quick
dialogicon
12 Posts 4 Posters 8.6k 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.
  • D Offline
    D Offline
    didu
    wrote on 21 May 2015, 12:20 last edited by
    #1

    Hello,

    Is it possible to set a Icon to a QML Dialog ?
    http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog.html
    It seems that there is nothing in documentation for it :(

    simple Dialog
    On windows, RC_ICONS give only a Icon to the main windows

    Thank in advance

    Q P 2 Replies Last reply 21 May 2015, 12:59
    0
    • D didu
      21 May 2015, 12:20

      Hello,

      Is it possible to set a Icon to a QML Dialog ?
      http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog.html
      It seems that there is nothing in documentation for it :(

      simple Dialog
      On windows, RC_ICONS give only a Icon to the main windows

      Thank in advance

      Q Offline
      Q Offline
      Quteroid
      wrote on 21 May 2015, 12:59 last edited by
      #2

      @didu
      I don't think this is possible in QtQuick. According to the documentation, the RC_ICONS feature is specific to both MS Windows and the main application window. There, it is not implemented via a component property (which I would consider more natural) but via something I would rather consider a QMakeFile hack. It also seems to rely on the Windows-specific .ico format for icons. Also note that showing icons in dialog titlebars is a feature that may not be common, enabled or available at all on some other platforms. So this feature shouldn't really play a significant role in app(lication) design decisions.

      That said, it should somehow be possible to achieve what you want via the lower level C++ side of the Qt world, using QStyleOptionTitleBar::icon and more general QIcon means. But likely not (yet?) via pure QML / QtQuick / JavaScript.

      1 Reply Last reply
      1
      • D didu
        21 May 2015, 12:20

        Hello,

        Is it possible to set a Icon to a QML Dialog ?
        http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog.html
        It seems that there is nothing in documentation for it :(

        simple Dialog
        On windows, RC_ICONS give only a Icon to the main windows

        Thank in advance

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 22 May 2015, 05:20 last edited by
        #3

        @didu If you are loading the QML from C++ side then you can use setWindowIcon. It will set icon on the title bar for main window as well as all its child windows.

        QGuiApplication app(argc, argv);
        app.setWindowIcon(QIcon("icon.png"));
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        

        Dialog invoked from main.qml will have that icon too.

        157

        1 Reply Last reply
        1
        • D Offline
          D Offline
          didu
          wrote on 22 May 2015, 07:57 last edited by didu
          #4

          @p3c0
          You are right it does. But it is the same behaviour as RC_ICONS ( http://doc.qt.io/qt-4.8/appicon.html ).
          main.qml and Dialog"child" have the icon.

          But theDialog in my app, that does not have a Icon, is a "child" of a StackView loaded by main.qml

          P 1 Reply Last reply 22 May 2015, 08:49
          0
          • D didu
            22 May 2015, 07:57

            @p3c0
            You are right it does. But it is the same behaviour as RC_ICONS ( http://doc.qt.io/qt-4.8/appicon.html ).
            main.qml and Dialog"child" have the icon.

            But theDialog in my app, that does not have a Icon, is a "child" of a StackView loaded by main.qml

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 22 May 2015, 08:49 last edited by
            #5

            @didu Tested something similar and it works. Can you post some code ?

            157

            1 Reply Last reply
            1
            • D Offline
              D Offline
              didu
              wrote on 22 May 2015, 13:18 last edited by
              #6

              @p3c0 Here is a "simple" test code
              The ProfileNameDialog has no Icon but the main.qml has :'(
              (I made test with and without "app.setWindowIcon")
              .pro

              ...
              RC_ICONS += "logo.ico"
              ...
              

              main.cpp

              #include <QApplication>
              #include <QQmlApplicationEngine>
              #include <QIcon>
              
              int main(int argc, char *argv[])
              {
                  QApplication app(argc, argv);
                  app.setWindowIcon(QIcon("logo.ico"));
                  QQmlApplicationEngine engine;
                  engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
              
                  return app.exec();
              }
              

              main.qml

              import QtQuick 2.4
              import QtQuick.Controls 1.3
              import QtQuick.Window 2.2
              import QtQuick.Dialogs 1.2
              
              ApplicationWindow {
                  title: qsTr("Hello World")
                  width: 640
                  height: 480
                  visible: true
              
                  Component {
                      id: mainId
              
                      MyMain {
              
                      }
                  }
              
                  StackView {
                      id: stack
                      anchors.fill: parent
                  }
              
                  Component.onCompleted: {
                      stack.push(mainId)
                  }
              }
              
              

              MyMain.qml

              import QtQuick 2.0
              import QtQuick.Controls 1.3
              
              Rectangle {
                  width: 100
                  height: 62
              
                  Button {
                      text: "Add"
              
                      ProfileNameDialog {
                          id: profileInputId
                      }
                      onClicked: profileInputId.visible = true
                  }
              }
              
              
              

              ProfileNameDialog.qml

              import QtQuick 2.0
              import QtQuick.Controls 1.2
              import QtQuick.Layouts 1.1
              import QtQuick.Dialogs 1.2
              
              Dialog {
                  id: profileInputId
                  title: "Profile name"
              
                  visible: false
                  standardButtons: StandardButton.Ok | StandardButton.Cancel
                  TextField {
                      id: profileNameId;
                      placeholderText: "Profile name"
                      width: parent ? parent.width : implicitWidth
                  }
              
                  onAccepted: visible = false
                  onRejected: visible = false;
              }
              
              
              P 1 Reply Last reply 23 May 2015, 05:35
              0
              • D didu
                22 May 2015, 13:18

                @p3c0 Here is a "simple" test code
                The ProfileNameDialog has no Icon but the main.qml has :'(
                (I made test with and without "app.setWindowIcon")
                .pro

                ...
                RC_ICONS += "logo.ico"
                ...
                

                main.cpp

                #include <QApplication>
                #include <QQmlApplicationEngine>
                #include <QIcon>
                
                int main(int argc, char *argv[])
                {
                    QApplication app(argc, argv);
                    app.setWindowIcon(QIcon("logo.ico"));
                    QQmlApplicationEngine engine;
                    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                
                    return app.exec();
                }
                

                main.qml

                import QtQuick 2.4
                import QtQuick.Controls 1.3
                import QtQuick.Window 2.2
                import QtQuick.Dialogs 1.2
                
                ApplicationWindow {
                    title: qsTr("Hello World")
                    width: 640
                    height: 480
                    visible: true
                
                    Component {
                        id: mainId
                
                        MyMain {
                
                        }
                    }
                
                    StackView {
                        id: stack
                        anchors.fill: parent
                    }
                
                    Component.onCompleted: {
                        stack.push(mainId)
                    }
                }
                
                

                MyMain.qml

                import QtQuick 2.0
                import QtQuick.Controls 1.3
                
                Rectangle {
                    width: 100
                    height: 62
                
                    Button {
                        text: "Add"
                
                        ProfileNameDialog {
                            id: profileInputId
                        }
                        onClicked: profileInputId.visible = true
                    }
                }
                
                
                

                ProfileNameDialog.qml

                import QtQuick 2.0
                import QtQuick.Controls 1.2
                import QtQuick.Layouts 1.1
                import QtQuick.Dialogs 1.2
                
                Dialog {
                    id: profileInputId
                    title: "Profile name"
                
                    visible: false
                    standardButtons: StandardButton.Ok | StandardButton.Cancel
                    TextField {
                        id: profileNameId;
                        placeholderText: "Profile name"
                        width: parent ? parent.width : implicitWidth
                    }
                
                    onAccepted: visible = false
                    onRejected: visible = false;
                }
                
                
                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 23 May 2015, 05:35 last edited by p3c0
                #7

                @didu Icon specified through RC_ICONS will not be available at runtime in the code. It is used to set the icon for the executable which is created after compiling.
                In your case you need to store the icon in Qt's Resource System by creating a .qrc file. After that it will be accessible from the code. Eg:

                app.setWindowIcon(QIcon("qrc:/images/logo.ico"));
                

                Another quick way to test it ls loading the ico file from a physical location. Eg:

                app.setWindowIcon(QIcon("D:/MyIcons/logo.ico"));
                

                The above should work too.
                But a more practical approach is to use the Resource files. More info here.

                157

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  didu
                  wrote on 26 May 2015, 11:39 last edited by
                  #8

                  @p3c0 Thanks you, you are right I had to use the Resource files.

                  Now with the same test code I have provided:
                  If I open the Dialog the first time, there is not Icon.
                  I close the Dialog.
                  I open a second time the Dialog, the Icon set with app.setWindowIconis shown.

                  Have you already face such problem ?

                  P 1 Reply Last reply 26 May 2015, 11:57
                  0
                  • D didu
                    26 May 2015, 11:39

                    @p3c0 Thanks you, you are right I had to use the Resource files.

                    Now with the same test code I have provided:
                    If I open the Dialog the first time, there is not Icon.
                    I close the Dialog.
                    I open a second time the Dialog, the Icon set with app.setWindowIconis shown.

                    Have you already face such problem ?

                    P Offline
                    P Offline
                    p3c0
                    Moderators
                    wrote on 26 May 2015, 11:57 last edited by
                    #9

                    @didu No. Never. In fact your code works perfectly.

                    157

                    1 Reply Last reply
                    1
                    • D Offline
                      D Offline
                      didu
                      wrote on 26 May 2015, 12:18 last edited by
                      #10

                      @p3c0 Ok Thanks a lot again for your time ! <3

                      P 1 Reply Last reply 26 May 2015, 12:21
                      0
                      • D didu
                        26 May 2015, 12:18

                        @p3c0 Ok Thanks a lot again for your time ! <3

                        P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 26 May 2015, 12:21 last edited by
                        #11

                        @didu You're Welcome :)
                        Happy Coding...

                        157

                        1 Reply Last reply
                        0
                        • HackSawH Offline
                          HackSawH Offline
                          HackSaw
                          wrote on 14 Jul 2021, 04:33 last edited by
                          #12

                          @p3c0 said in Icon Dialog:

                          @didu Icon specified through RC_ICONS will not be available at runtime in the code. It is used to set the icon for the executable which is created after compiling.
                          In your case you need to store the icon in Qt's Resource System by creating a .qrc file. After that it will be accessible from the code. Eg:

                          app.setWindowIcon(QIcon("qrc:/images/logo.ico"));
                          

                          Another quick way to test it ls loading the ico file from a physical location. Eg:

                          app.setWindowIcon(QIcon("D:/MyIcons/logo.ico"));
                          

                          The above should work too.
                          But a more practical approach is to use the Resource files. More info here.

                          I was facing a similar issue with the icon being loaded successfully from its physical location but not from the resource file. So I tried

                          app.setWindowIcon(QIcon(":/Images/IconFile.ico"));
                          

                          where "qrc" is removed which worked seamlessly.

                          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