summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-10-10 09:28:12 +0200
committerLars Knoll <lars.knoll@qt.io>2016-10-10 16:01:48 +0200
commit102fa9b6db82ecd2b95d168912fde0c8bc3798b3 (patch)
tree5bf934c323dcafb67cb508ace579110191ad782d /examples
parenta6be2d77aa6dc9f834b971eaff749a02cf982525 (diff)
parentfff4477661ae240c43088fa6d9069ccf969dbee8 (diff)
Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts: examples/quick/quickwidgets/quickwidget/main.cpp src/qml/jsruntime/qv4jsonobject.cpp src/qml/jsruntime/qv4qobjectwrapper.cpp src/qml/jsruntime/qv4qobjectwrapper_p.h src/qml/qml/qqmlengine.cpp src/qml/qml/qqmlpropertycache.cpp src/qml/qml/qqmlpropertycache_p.h src/quick/items/qquickanimatedsprite.cpp src/quick/items/qquickitem.cpp src/quick/items/qquickitem.h src/quick/items/qquickitem_p.h src/quick/items/qquickview_p.h src/quick/scenegraph/qsgcontext.cpp src/quick/scenegraph/qsgdefaultrendercontext.cpp Change-Id: I172c6fbff97208f21ed4c8b6db3d1747a889f22b
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp30
-rw-r--r--examples/quick/quickwidgets/quickwidget/rotatingsquare.qml6
2 files changed, 28 insertions, 8 deletions
diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp
index 2f73447a5d..6bb6722e02 100644
--- a/examples/quick/quickwidgets/quickwidget/main.cpp
+++ b/examples/quick/quickwidgets/quickwidget/main.cpp
@@ -39,6 +39,7 @@
****************************************************************************/
#include <QQuickWidget>
+#include <QQuickItem>
#include <QQmlError>
#include <QtWidgets>
#include "fbitem.h"
@@ -51,8 +52,9 @@ public:
private slots:
void quickWidgetStatusChanged(QQuickWidget::Status);
void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message);
- void grabToFile();
- void renderToFile();
+ void grabFramebuffer();
+ void renderToPixmap();
+ void grabToImage();
void createQuickWidgetsInTabs(QMdiArea *mdiArea);
private:
@@ -93,8 +95,9 @@ MainWindow::MainWindow()
setCentralWidget(centralWidget);
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(tr("Grab to image"), this, &MainWindow::grabToFile);
- fileMenu->addAction(tr("Render to pixmap"), this, &MainWindow::renderToFile);
+ fileMenu->addAction(tr("Grab framebuffer"), this, &MainWindow::grabFramebuffer);
+ fileMenu->addAction(tr("Render to pixmap"), this, &MainWindow::renderToPixmap);
+ fileMenu->addAction(tr("Grab via grabToImage"), this, &MainWindow::grabToImage);
fileMenu->addAction(tr("Quit"), qApp, &QCoreApplication::quit);
QMenu *windowMenu = menuBar()->addMenu(tr("&Window"));
@@ -143,8 +146,7 @@ void MainWindow::sceneGraphError(QQuickWindow::SceneGraphError, const QString &m
template<class T> void saveToFile(QWidget *parent, T *saveable)
{
- QString t;
- QFileDialog fd(parent, t, QString());
+ QFileDialog fd(parent);
fd.setAcceptMode(QFileDialog::AcceptSave);
fd.setDefaultSuffix("png");
fd.selectFile("test.png");
@@ -152,19 +154,31 @@ template<class T> void saveToFile(QWidget *parent, T *saveable)
saveable->save(fd.selectedFiles().first());
}
-void MainWindow::grabToFile()
+void MainWindow::grabFramebuffer()
{
QImage image = m_quickWidget->grabFramebuffer();
saveToFile(this, &image);
}
-void MainWindow::renderToFile()
+void MainWindow::renderToPixmap()
{
QPixmap pixmap(m_quickWidget->size());
m_quickWidget->render(&pixmap);
saveToFile(this, &pixmap);
}
+void MainWindow::grabToImage()
+{
+ QFileDialog fd(this);
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.setDefaultSuffix("png");
+ fd.selectFile("test_grabToImage.png");
+ if (fd.exec() == QDialog::Accepted) {
+ QMetaObject::invokeMethod(m_quickWidget->rootObject(), "performLayerBasedGrab",
+ Q_ARG(QVariant, fd.selectedFiles().first()));
+ }
+}
+
int main(int argc, char **argv)
{
QApplication app(argc, argv);
diff --git a/examples/quick/quickwidgets/quickwidget/rotatingsquare.qml b/examples/quick/quickwidgets/quickwidget/rotatingsquare.qml
index 0c25eddf88..03b1114d20 100644
--- a/examples/quick/quickwidgets/quickwidget/rotatingsquare.qml
+++ b/examples/quick/quickwidgets/quickwidget/rotatingsquare.qml
@@ -57,4 +57,10 @@ Rectangle {
anchors.centerIn: parent
text: "Qt Quick running in a widget"
}
+
+ function performLayerBasedGrab(fn) {
+ root.grabToImage(function(result) {
+ result.saveToFile(fn);
+ });
+ }
}