Qt World Summit: Submit your Presentation

[Solved] Yet another QWidget in QML Question

  • I am interfacing to a fingerprint scanner. The scanner driver provides the ability to write image data to a "window" directly. I have no information about HOW the driver writes the image data.

    A simple Qt C++ application works just fine.

    In the following snippet, "core" is an interface to the driver and "vizWidget" is the target QWidget that will display the image.

    The onStartButtonClicked() slot tells the driver to begin acquiring a type of fingerprint. The driver is provided "vizWidget" handle and a region (RECT) to draw the live image.

    No problem, works perfectly! The vizWidget displays the live images as expected.

    void MainWindow::setupWidget(void)
    winHandle = (void*)vizWidget->winId();

    connect(startButton, SIGNAL(clicked()), this, SLOT(onStartButtonClicked()));


    void MainWindow::onStartButtonClicked(void)

    So now I need to put the vizWidget in my QML application.
    I wrap the QWidget in QGraphicsProxyWidget...

    class VisualizationWidget : public QGraphicsProxyWidget


    QWidget*                m_widget;


    VisualizationWidget(QGraphicsItem* parent =0)
        : QGraphicsProxyWidget(parent), m_widget(NULL)
        m_widget = new QWidget;
        m_widget->setGeometry(QRect(0, 0, 300, 300));
        m_widget->setMinimumSize(300, 300);
        m_widget->setMaximumSize(300, 300);
    Q_INVOKABLE void*   handle(void)          { return m_widget->winId(); }


    ...and add it to my view...

    VisualizationWidget {
    id: vizWin
    width: 300
    height: 300
    anchors.top: workspace.top
    anchors.topMargin: 10
    anchors.left: workspace.left
    anchors.leftMargin: 10

    Connections {
        target: core
        onScannerSelected: {


    The VisualizationWidget is displayed but it does not display the live images.

    Both cases share the same core and device interface code (a DLL) and I have confirmed that the sequence for setting up and executing the fingerprint operation is identical in both cases.

    I have also tried many variations of the VisualizationWidget but have had ZERO success.
    Note that substituting the QWidget with a QPushButton works (the button works fine as a button).

    So my question seems to be related to the differences of QWidget in the two environments.

  • Hi,

    Did you have to set the flag ItemHasNoContents with :
    setFlag(QGraphicsItem.ItemHasNoContents, False)

  • Yes I tried that, but it only results in hiding the widget.

  • You should also reimplement QGrsaphicsItem::paint()

  • [quote author="deimos" date="1316619070"]You should also reimplement QGrsaphicsItem::paint()[/quote]

    Yes, I thought that to. But to do what? The image data is provided by a "black box". I don't provide any code to use the data and there is no notification that data is available. The "black box" (OEM driver) just takes a window handle and a region and mysteriously shows live image data in the C++ widget. The OEM driver API does not supply information about the mechanisms used to perform the data transfer.

  • Thank everyone, I finally solved this problem by using
    QmlApplicationViewer viewer;
    pViewContext = viewer.rootContext();
    vizWinHandle = (void*) viewer.viewport()->winId();

    in main.cpp and passing the coordinates of an Image to the OEM driver from QML.

    NOTE: This is not an ideal solution for most applications because if the window is moved or resized, the region does not follow. But, it just so happens that my application is required to run in full screen so this problem is moot.

    The problem with QGraphicsProxyWidget is not that I could not get a proper HWIN. The problem was that that QGraphicsProxyWidget does not provide the actual widget coordinates. So when passing the rectangle to the OEM driver, the specified region was off the screen.

Log in to reply