Qt 6.11 is out! See what's new in the release
blog
QPixmap::grabWindow how to grab mouse cursor ?
-
Hi,
That's not the goal of
grabWindow, however what you can do is draw the point of interest on the pixmap you get. -
Hi,
That's not the goal of
grabWindow, however what you can do is draw the point of interest on the pixmap you get. -
@SGaist How to convert QCursor to QPixmap ?
QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId()); QPainter painter(&pixmap); painter.drawPixmap(500,500,QCursor(Qt::ArrowCursor).pixmap()); -
@sonichy
hi
I dont think you can return a pixmap for the system cursors.
Its only if you constructed a custom one using
QCursor::QCursor(const QPixmap &pixmap, int hotX = -1, int hotY = -1)
As far as I know. -
Do you mean QCursor::pos ?
-
Do you mean QCursor::pos ?
@SGaist Construct a QWidget to get cursor::pos() !
#include <QApplication> #include <QStandardPaths> #include <QWidget> #include <QScreen> #include <QClipboard> #include <QDateTime> #include <QPainter> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget *widget = new QWidget; QScreen *screen = QGuiApplication::primaryScreen(); QPixmap pixmap = screen->grabWindow(0); QPixmap pixmap_mouse(":/mouse.png"); QPainter painter(&pixmap); painter.drawPixmap(widget->cursor().pos(),pixmap_mouse); QApplication::clipboard()->setPixmap(pixmap, QClipboard::Clipboard); QDateTime time = QDateTime::currentDateTime(); QString filename = time.toString("yyyyMMddhhmmss") + ".jpg"; QString path = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first() + "/" + filename; pixmap.save(path,0,100); return 0; } -
@SGaist Construct a QWidget to get cursor::pos() !
#include <QApplication> #include <QStandardPaths> #include <QWidget> #include <QScreen> #include <QClipboard> #include <QDateTime> #include <QPainter> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget *widget = new QWidget; QScreen *screen = QGuiApplication::primaryScreen(); QPixmap pixmap = screen->grabWindow(0); QPixmap pixmap_mouse(":/mouse.png"); QPainter painter(&pixmap); painter.drawPixmap(widget->cursor().pos(),pixmap_mouse); QApplication::clipboard()->setPixmap(pixmap, QClipboard::Clipboard); QDateTime time = QDateTime::currentDateTime(); QString filename = time.toString("yyyyMMddhhmmss") + ".jpg"; QString path = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first() + "/" + filename; pixmap.save(path,0,100); return 0; }