Skip to content

Instantly share code, notes, and snippets.

@codec-abc
Created November 30, 2020 19:09
Show Gist options
  • Select an option

  • Save codec-abc/bc3d8797e8894de5e33430ab66bb100b to your computer and use it in GitHub Desktop.

Select an option

Save codec-abc/bc3d8797e8894de5e33430ab66bb100b to your computer and use it in GitHub Desktop.
#include <QtGui/QGuiApplication>
#include <QApplication>
#include <QMainWindow>
#include <QPainter>
#include <QObject>
#include <QClipboard>
#include <QtGui/QImage>
#include <QtGui/QColor>
#include <QtCore/QStringList>
#include <QtCore/QCommandLineParser>
#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <iostream>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMainWindow w;
QClipboard *clipboard = QGuiApplication::clipboard();
QPixmap base(500, 500);
base.fill(Qt::blue);
QPainter* painter = new QPainter(&base);
QHBoxLayout *layout = new QHBoxLayout;
QPushButton *button1 = new QPushButton("Paste clipboard onto image");
QLabel *label = new QLabel("Image display");
QObject::connect(
button1, &QPushButton::clicked,
[&]( const bool newValue ) {
base.fill(Qt::red);
QPixmap overlay = QPixmap::fromImage(clipboard->image());
painter->drawPixmap(10, 10, overlay);
label->setPixmap(base);
}
);
label->setPixmap(base);
layout->addWidget(button1);
layout->addWidget(label);
w.setCentralWidget(new QWidget);
w.centralWidget()->setLayout(layout);
w.show();
int returnCode = app.exec();
return returnCode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment