我如何知道正在调用 QGraphicsItem::paint() 进行打印?

发布于 2024-10-19 11:49:13 字数 635 浏览 8 评论 0原文

我有一个自定义的QGraphicsItem,它显示大型(数百MB 压缩的多通道)图像。现在运作得很好。

这个想法是仅加载当前视图比例和图形视图端口所需的扫描线。并将显示划分为在单独线程中构建的图块。 paint() 函数仅构造图块并将它们提供给 QThreadPool。它还检查并绘制任何已完成的图块。有更多代码处理线程/可运行对象和项目之间的事件。但这是基本部分。

目标是提供响应式 UI。当项目自行更新时,UI 不会被阻止。一切都很顺利,直到我尝试弄清楚如何打印它。

问题是我需要知道对绘制函数的特定调用是由打印而不是屏幕更新引起的。这需要阻塞主线程,直到我的所有图块完成并绘制到画家(或者打印的页面将是空白,因为paint()立即返回)

它还有助于调整采样率,因为打印机的分辨率比屏幕。

所以我的问题归结为:如何确定传递给我的 paint()QPainter 是屏幕还是打印机。更好的是,我可以判断调用是用于打印预览还是实际打印?

谢谢。

I have a custom QGraphicsItem that display large (100s of MB compressed, mutli-channel) images. It's working pretty well right now.

The idea is only load scanlines that are needed for current view scale and graphics view port. And divide the display into tiles that are built in separate threads. The paint() function only constructs the tiles and feed them to QThreadPool. It also checks for and draw any tiles that are done. There are more code handling the events between the threads/runnables and the item. But this is the basic part.

The goal is to provide a responsive UI. When the item is updating itself, UI is not blocked. It all work well until I tried to figure how to print it.

The problem is I need to know a particular call to my paint function is resulted from a print instead of on screen update. This is needed to block the main thread until all my tiles are done and plotted to the painter (or the printed page will be blank since paint() returns right away)

It also helps to adjust the sample rate since the printer has higher resolution than screen.

So my question comes down to this: How can I find out if the QPainter passed to my paint() is a screen or a printer. Better yet, can I tell if the invocation is for print preview or actual print?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有伤那来痛 2024-10-26 11:49:13

只是一个想法,目前没有打印机来测试它。

QPainter 中有一个 device() 方法QPainter 返回该画家当前正在其上绘画的绘画设备的类,如果画家未处于活动状态,则返回 0。绘画设备可以通过QWidgetQImageQPixmapQGLPixelBufferQPicture来实现em> 和 QPrinter 子类。所以我相信如果您检查您的设备是否为 QPrinter 类型,这会意味着您现在正在打印。

像这样:

QPaintDevice* device = painter->device();
if (dynamic_cast<QPrinter*>(device)!=NULL)
    qDebug() << "QPrinter";
else if (dynamic_cast<QWidget*>(device)!=NULL)
    qDebug() << "QWidget";
else if (dynamic_cast<QImage*>(device)!=NULL)
    qDebug() << "QImage";
else if (dynamic_cast<QPixmap*>(device)!=NULL)
    qDebug() << "QPixmap";
else if (dynamic_cast<QPicture*>(device)!=NULL)
    qDebug() << "QPicture";
else
    qDebug() << "something else";

希望这有帮助,问候

Just an idea, don't have a printer right now to test it.

There is a device() method in QPainter class which returns the paint device on which this painter is currently painting, or 0 if the painter is not active. The paint device could be implemented by the QWidget, QImage, QPixmap, QGLPixelBuffer, QPicture, and QPrinter subclasses. So I believe if you will check if your device is of QPrinter type, this would mean you're printing right now.

Smth like this:

QPaintDevice* device = painter->device();
if (dynamic_cast<QPrinter*>(device)!=NULL)
    qDebug() << "QPrinter";
else if (dynamic_cast<QWidget*>(device)!=NULL)
    qDebug() << "QWidget";
else if (dynamic_cast<QImage*>(device)!=NULL)
    qDebug() << "QImage";
else if (dynamic_cast<QPixmap*>(device)!=NULL)
    qDebug() << "QPixmap";
else if (dynamic_cast<QPicture*>(device)!=NULL)
    qDebug() << "QPicture";
else
    qDebug() << "something else";

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文