summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-30 00:16:40 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-30 00:16:40 +0200
commit0bf14044178d7aa212ac7e28530f9077790a3df4 (patch)
tree4c403571abbc5e18c6962ba67d9cb584d8e121c4 /examples
parent0aea009425242417bffdb171c8eca02ff52f4a7b (diff)
parent79cfc8788d6267eeb263983466ba21758f618dcd (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: tests/auto/quick/qquicktext/tst_qquicktext.cpp Change-Id: I241cd418bb7e7b95e0a0a2ee4c465d48be2a5582
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 65258d958e..3f3638a43f 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>
@@ -50,8 +51,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();
private:
QQuickWidget *m_quickWidget;
@@ -91,8 +93,9 @@ MainWindow::MainWindow()
setCentralWidget(centralWidget);
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
- fileMenu->addAction(tr("Grab to imFage"), 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);
}
@@ -113,8 +116,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");
@@ -122,19 +124,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);
+ });
+ }
}