DPFPApi how to convert data_blob to qpixmap in qt5 - qt

I'm currently integrating DigitalPersona U.are.U into a Qt Application. I've been able to obtain image DATA_BLOB from the DPFPApi. The only problem I have now is to preview the image by setting pixmap to a QLabel. I've tried using
QPixmap pix(QByteArray((const char*)imgBlob->pbData, imgBlob->cbData));
but that returns a null pixmap. How can I achieve that?

If the image is a bitmap, use the QBitmap::fromData function to create the QPixmap. It is documented here.
Or use QPixmap::loadFromData to allow Qt to attempt to detect the data format based on information in the image header.

Related

Using OpenGL frame buffer objects with Qt (QOpenGLWidget), how to disable multisampling when drawing to frame buffer

As the title suggests, I'm using Qt for OpenGL drawing, and with QOpenGLWidget I can turn on multisampling for the main screen buffer with QSurfaceFormat's setSamples() function. This works fine and looks pretty nice. However, I'm also drawing into a custom frame buffer (using glGenFramebuffers, glBindFramebuffer(), etc) in the background, where I don't want anti-aliasing (since it's drawing using color encoding for selection purposes), but it seems to be inheriting the multi-sampling from the main QOpenGLWidget somehow. Any ideas on how to disable that, to use multisampling in the main window but not in my own custom off-screen frame buffers?
Multisampled rendering is enabled or disabled by using the glEnable/Disable(GL_MULTISAMPLE). This state is not part of the framebuffer's state; it's regular context state. As such, even when you switch framebuffers, that state will be unaffected.
Additionally, the multisample enable/disable switch doesn't mean anything if your attached images don't have multiple samples. If you're creating images for non-multisampled rendering, there's no reason to create them with multiple samples. So create single-sample images.
Well, couldn't find a way to disable it or avoid it in my OpenGL code, but if I set the default format to have 0 samples and the format of the QOpenGLWidget to have 2/4/8/whatever, then the framebuffer object won't use anti-aliasing when it's created.

display Qprocess output window inside the QT mainwindow

how to display Qprocess output window inside the QT mainwindow? I am calling ffplay by Qprocess. the video playing in a detached window? how would i play the video in same application QTwindow
I don't know ffplay but it seems that ffplay is opening the window by itself. One approach is that you could try to get the current image and display that in your mainwindow. Every time a new image is available you have to replace the image in your ui with the new one. Of course you have to keep synchronization in mind, since this application is not single-threaded.
In general your approach looks not right. You shouldn't call a program to do that kind of task. Normally you use a library for that.
You should have a look at this example to get an idea what I'm talking about: https://doc.qt.io/qt-5/qtwidgets-widgets-movie-example.html

How to save image of application containing QGLWidget

I am looking for some example code that I can use to save an image of my Qt application. The application is a QMainWindow that contains a QGLWidget. I want to be able to screen capture all the GUIs (including the QGLWidget rendering) but have not been able to find any example code for this.
What I've tried:
QPixmap pixmap = QPixMap::grabWidget(QApplication::activeWindow);
pixmap.save(QString("test.png"));
This only save the GUIs but leaves a black background around the QGLWidget.
Anyone know of a technique for doing this in Qt 4.8.4?
Thanks,

Is there a way to access the image on the QWidget's backing store?

I'm doing some compositing inside the paintEvent() in a custom widget. Some of the compositing is done when some areas are already painted, and I need access to the current contents painted so far.
So, I'm looking for a way to access the image contents of the current backing store during a paintEvent. I've looked at QBackingStore, but there's nothing there that directly gives me access to the backing store bitmap. Is there some API, perhaps private, that could be used to provide that?
If not, I'll have to resort to painting on an explicit pixmap and rendering that pixmap onto the widget.
It is possible, but it is not portable. The QBackingStore is just a wrapper class around a QImage buffer on most platforms, but I suppose this is not guaranteed. I've researched this issue when writing the QuickWidget. A cast is needed:
QImage * image = dynamic_cast<QImage*>(backingStore()->paintDevice());
if (image != 0) // it's an image, do something with it
Be careful though not to cause the QImage to detach. Things such as resizing are off limits.
Check the QuickWidget out at:
https://code.google.com/p/quickwidget/

OpenGL rendering to a QML item

I have a QML file which contains a layout of QML items and now I want one of those items to be a QGLWidget. i.e. I want to render to a specific QML item.
Is anyone aware of how to do this?
The simplest way I suppose it to provide QML a new custom component implemented in C++. I couldn't find anything ready.
You could subclass the QDeclarativeItem and implement your OpenGL code in the paint function after using the QPainter::beginNative() function. After that you can "export" your new custom item to QML this way. This is quite simple and should work, but you'll have to setup the viewport of you QDeclarativeView to be a QGLWidget, something like this:
QDeclarativeView view;
// This is needed because OpenGL viewport doesn't support partial updates.
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdateMode);
view.setViewport(new QGLWidget);
or you'll have to use the opengl graphics system for the entire application.
Another way is using QML/3D.
This thread will give you some other information.

Resources