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. Screenshot of expanded combobox
Forum Updated to NodeBB v4.3 + New Features

Screenshot of expanded combobox

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Montjet
    wrote on 18 Oct 2018, 15:53 last edited by Montjet
    #1

    Hi,
    I have problem with screenshot of combobox.
    Code:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.4
    
    Window
    {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Item
        {
            id: root
            anchors.fill: parent
            focus: true
    
            ComboBox
            {
                model: ["First", "Second", "Third"]
            }
    
            Keys.onDigit1Pressed:
            {
                root.grabToImage(function(result)
                {
                    result.saveToFile("test.png");
                    console.log("file has been saved");
                }, Qt.size(root.width, root.height));
            }
        }
    }
    

    Screenshot doesn't contain popup, but button is visible.
    What's wrong with my code?

    Tested on Qt 5.11.1 and 5.9.2

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 18 Oct 2018, 16:02 last edited by
      #2

      Hi
      Wont the popup close when you press a key to take screen shot ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Montjet
        wrote on 18 Oct 2018, 16:10 last edited by
        #3

        Unfortunately, I also need popup in the screenshot :(

        M 1 Reply Last reply 18 Oct 2018, 18:40
        0
        • M Montjet
          18 Oct 2018, 16:10

          Unfortunately, I also need popup in the screenshot :(

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 18 Oct 2018, 18:40 last edited by
          #4

          @Montjet
          hi
          Could you try
          combo.popup.visible = true
          in Keys.onDigit1Pressed:
          https://stackoverflow.com/questions/38229511/how-to-open-combobox-dropdown-menu

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Montjet
            wrote on 18 Oct 2018, 19:20 last edited by Montjet
            #5

            @mrjj said in Screenshot of expanded combobox:

            combo.popup.visible = true

            it doesn't work :(

            M 1 Reply Last reply 18 Oct 2018, 22:34
            0
            • M Montjet
              18 Oct 2018, 19:20

              @mrjj said in Screenshot of expanded combobox:

              combo.popup.visible = true

              it doesn't work :(

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 18 Oct 2018, 22:34 last edited by
              #6

              @Montjet
              Did you try anything else from the link ?
              To try to open it before the shot ?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Montjet
                wrote on 19 Oct 2018, 06:58 last edited by Montjet
                #7

                Yes, I also tried to add parent of Popup:

                import QtQuick 2.9
                import QtQuick.Controls 2.2
                import QtQuick.Window 2.2
                
                Window
                {
                    id: window
                    visible: true
                    width: 640
                    height: 480
                    title: qsTr("Hello World")
                    Item
                    {
                        id: root
                        anchors.fill: parent
                        focus: true
                        ComboBox
                        {
                            id: combo
                            width: 200
                            model: [ "First", "Second", "Third" ]
                            popup.parent: window.contentItem;
                            popup.modal: true;
                        }
                        Keys.onDigit1Pressed:
                        {
                
                           console.log("bbbb");
                            combo.popup.visible = true
                            root.grabToImage(function(result)
                                        {
                                            result.saveToFile("test.png");
                                            console.log("file has been saved");
                                        }, Qt.size(root.width, root.height));
                            combo.popup.visible = true
                        }
                    }
                }
                

                Nothing works for me :(

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Montjet
                  wrote on 19 Oct 2018, 07:15 last edited by
                  #8

                  Oh, but this code works well:

                  // ...
                              Window.contentItem.grabToImage(function(result)
                                          {
                                              result.saveToFile("test.png");
                                              console.log("file has been saved");
                                          }, Qt.size(root.width, root.height));
                  // ...
                  
                  

                  I need to take a screenshot of selected items, so my problem is still not resolved :(

                  M G 2 Replies Last reply 19 Oct 2018, 07:53
                  0
                  • M Montjet
                    19 Oct 2018, 07:15

                    Oh, but this code works well:

                    // ...
                                Window.contentItem.grabToImage(function(result)
                                            {
                                                result.saveToFile("test.png");
                                                console.log("file has been saved");
                                            }, Qt.size(root.width, root.height));
                    // ...
                    
                    

                    I need to take a screenshot of selected items, so my problem is still not resolved :(

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 19 Oct 2018, 07:53 last edited by
                    #9

                    @Montjet
                    Hmm
                    Try with timer then
                    http://doc.qt.io/qt-5/qml-qtqml-timer.html#details

                    so set it high enough till u can open combo and select item and
                    it should take shot with the dropdown visible.

                    1 Reply Last reply
                    0
                    • M Montjet
                      19 Oct 2018, 07:15

                      Oh, but this code works well:

                      // ...
                                  Window.contentItem.grabToImage(function(result)
                                              {
                                                  result.saveToFile("test.png");
                                                  console.log("file has been saved");
                                              }, Qt.size(root.width, root.height));
                      // ...
                      
                      

                      I need to take a screenshot of selected items, so my problem is still not resolved :(

                      G Offline
                      G Offline
                      GrecKo
                      Qt Champions 2018
                      wrote on 19 Oct 2018, 08:08 last edited by
                      #10

                      @Montjet said in Screenshot of expanded combobox:

                      I need to take a screenshot of selected items, so my problem is still not resolved :(

                      What's the problem ?
                      When tested this seem to correctly grabs a screenshot of the opened combobox.
                      What more do you want ?

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        Montjet
                        wrote on 19 Oct 2018, 09:06 last edited by Montjet
                        #11

                        My main project is based on Qt 5.9.2.
                        For this solution I got error... :

                        QML QQuickRootItem: grabToImage: item has no QML engine
                        

                        It's difficult to solve this issue ;(

                        @GrecKo
                        Sometimes I need to take screenshot of a single rectangle that contains comboBox, not an entire window.

                        Example:

                        import QtQuick 2.9
                        import QtQuick.Controls 2.2
                        import QtQuick.Window 2.2
                        
                        Window
                        {
                            id: window
                            visible: true
                            width: 640
                            height: 480
                            title: qsTr("Hello World")
                            Item
                            {
                                id: root1
                                anchors.fill: parent
                                focus: true
                                ComboBox
                                {
                                    id: combo1
                                    width: 200
                                    model: [ "First", "Second", "Third" ]
                                    popup.parent: root1;
                                    popup.modal: false;
                                }
                                Keys.onDigit1Pressed:
                                {
                        
                                   console.log("bbbb");
                                    combo1.popup.visible = true
                                    window.contentItem.grabToImage(function(result)
                                                {
                                                    result.saveToFile("test.png");
                                                    console.log("file has been saved");
                                                }, Qt.size(root1.width, root1.height));
                                    combo1.popup.visible = true
                                }
                            }
                        
                            Item
                            {
                                id: root2
                                anchors.fill: parent
                                focus: true
                                ComboBox
                                {
                                    id: combo2
                                    width: 200
                                    model: [ "First", "Second", "Third" ]
                                    popup.parent: root2;
                                    popup.modal: false;
                                    anchors.right: parent.right
                                }
                                Keys.onDigit2Pressed:
                                {
                        
                                   console.log("bbbb");
                                    combo2.popup.visible = true
                                    window.contentItem.grabToImage(function(result)
                                                {
                                                    result.saveToFile("test.png");
                                                    console.log("file has been saved");
                                                }, Qt.size(root2.width, root2.height));
                                    combo2.popup.visible = true
                                }
                            }
                        }
                        
                        

                        I want to take a screenshot of only one combobox.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          GrecKo
                          Qt Champions 2018
                          wrote on 19 Oct 2018, 09:44 last edited by
                          #12

                          You want to screenshot only the combobox popup ?
                          Does that do what you want : combo1.popup.contentItem.grabToImage ?

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Montjet
                            wrote on 19 Oct 2018, 10:01 last edited by Montjet
                            #13

                            I want to screenshot of root2 or root1.

                            Timer also doesn't work

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Montjet
                              wrote on 19 Oct 2018, 12:38 last edited by Montjet
                              #14

                              Ok, I fixed it. I had older version of import QtQuick.Window -> 2.0

                              1 Reply Last reply
                              0

                              3/14

                              18 Oct 2018, 16:10

                              topic:navigator.unread, 11
                              • Login

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