如何在QT中使用Paint事件(WM_Paint)进行截图
how to take screenshot with Paint event (WM_Paint) in QT
我正试图用QT中的Paint事件(WM_Paint)事件截图,但我不知道如何,我用这个代码来截图,但它不是很好当桌面发生一些变化时,它必须进行截图,而不是每1000毫秒用计时器进行截图
void MainWindow::shootScreen()
{
originalPixmap = QPixmap(); // clear image for low memory situations
// on embedded devices.
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
//emit getScreen(originalPixmap);
updateScreenshotLabel();
}
void MainWindow::updateScreenshotLabel()
{
this->ui->label_2->setPixmap(originalPixmap.scaled(this->ui->label_2- >size(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation));
}
在您感兴趣的小部件上使用QObject::installEventFilter
,然后检查适当的事件。例如,在MainWindow
ui初始化中:
void MainWindow::yourUiInitFunc()
{
exampleWidget = new QWidget;
...
exampleWidget->installEventFilter(this);
...
}
然后重新实现eventFilter
:
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == exampleWidget && event->type() == QEvent::KeyPress)
shootScreen();
return QMainWindow::eventFilter(obj, event);
}
谢谢你,Jon Harper,你的代码很有用,但是我改变了一些东西你的代码只是工作时,一些按键事件在我的项目形式,但我添加了油漆方法,你的如果,现在它工作在Windows事件太
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == this && QEvent::Paint == event->type()) {
shootScreen();
}
return false;
}
相关文章:
- "WM" C++是什么意思?
- 如何访问委托的paint()函数中的另一个索引?
- 直接在QlistView上绘制小部件,并使用QStyleDitemdelegate :: Paint()
- QT4:在所有qgraphicsItem上的单个qgraphictem rapers paint()上的update()
- 什么是窗口最大化/最小化/恢复的WM Windows消息
- Qt. 方法显示文本() 如果我在 QStyledItemDelegate 中定义了 paint() 方法不起作用
- 如何在我的子类控件paint方法中在默认的paint结果之上绘制一些东西
- 请求X11在C或C++中合成WM的图像
- Qt QTableView paint() 事件无限期交付,占用 100% 的 CPU 内核
- Paint QPushButton with QLinearGradient
- Paint Job Estimator C++
- Q即使宽度和高度都为非零,也不调用ridget paint
- Qt paint事件崩溃
- 如何使用插槽实时更新paint()
- paint函数中的QStyleOptionViewItem参数-如何处理它
- 除非先使用MS Paint打开/保存文件,否则带有QRCode位图的LoadImage()将失败
- 如何将使用Qt Paint Application绘制的图像传输到Mat openCV
- OpenGL新手,致力于"paint"程序
- 如果在WM/CE平台中用于卸载,DMProcessConfigXML将关闭正在运行的应用程序
- 重写QGraphicsItem的paint()和mouseEvents()