Screenshot of expanded combobox
-
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
-
Hi
Wont the popup close when you press a key to take screen shot ? -
@Montjet
hi
Could you try
combo.popup.visible = true
in Keys.onDigit1Pressed:
https://stackoverflow.com/questions/38229511/how-to-open-combobox-dropdown-menu -
-
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 :(
-
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 :(
-
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 :(
@Montjet
Hmm
Try with timer then
http://doc.qt.io/qt-5/qml-qtqml-timer.html#detailsso set it high enough till u can open combo and select item and
it should take shot with the dropdown visible. -
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 :(
@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 ? -
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.
-
You want to screenshot only the combobox popup ?
Does that do what you want :combo1.popup.contentItem.grabToImage
?