Third part library: Wrapping a QWidget
-
Hi all, I'm evaluating the possibility to move my applications from Windows to Linux. For this reason, I decided to try Qt (coming from C# .NET).
For my job I develop industrial software based on Third-party library. This library is written in C, and very open supporting a wide range of operating systems and providing an interface also for C++.
Because the main purpose of this software library is image processing, it has one (and only one!) UI component, that is used to display images and overlay.
Actually, it is not a true UI component, but the library has the ability to "open" a native window both on win32 and linux (X11 window, in the latter case), and this is exploited both to build .Net component and Qt QWidget.So here is the point: I have a running example of a QWidget inherited class, that simply opens this window inside the widget itself, and then redefines the "resize" method (using winID() and some other X11 attributes) to resize the base window in order to fit the widget. This works well using standard widgets UI, but I'd like to "wrap" it in a QML component, in order to develop my UI using QML, and let C++ manage the business logic (it is mainly a multithread application, that acquire and process images coming from multiple digital cameras, displaying results inside the windows described above).
What I did is to derive a QDeclarativeItem containing the widget and a QGraphicsProxyItem to manage it. Unfortunately, it doesn't show anything. Could someone please give some advice on how to proceed? I attach the example code of the widget, but it could not work of course because of missing runtime libraries...
@
// --------------------------------------------------------------
// QLibraryWindow.h : Class used for opening Library windows in Qt
// --------------------------------------------------------------#include <qwidget.h>
#include "LibraryCpp.h"class QLibraryWindow: public QWidget
{
Q_OBJECTpublic:
QLibraryWindow(QWidget *parent=0, long Width=0, long Height=0);
virtual ~QLibraryWindow(void);Hlong WindowID(void) {return WinID;}
protected:
void resizeEvent(QResizeEvent*);private:
Hlong WinID;
void OpenWindow(void);
};// --------------------------------------------------------------
// QLibraryWindow.cpp : Implementation of the class QLibraryWindow
// --------------------------------------------------------------#include "LibraryCpp.h"
#include "qLibrarywindow.h"
#ifdef Q_WS_X11
#if QT_VERSION >= 0x040000
#include <QX11Info>
#endif
#include <X11/Xlib.h>
#endifQLibraryWindow::QLibraryWindow(QWidget *parent, long Width, long Height)
: QWidget(parent)
{
resize(Width,Height);
show();
OpenWindow();
}QLibraryWindow::~QLibraryWindow(void)
{
using namespace Library;close_window(WindowID());
}// Open a Library window inside the QLibraryWindow widget
void QLibraryWindow::OpenWindow(void)
{
using namespace Library;#ifdef Q_WS_X11
// In Qt versions older version 3.3, it is necessary to temporarily
// change the SubstructureRedirectMask attribute of a Qt widget
// in order to be able to open a Library window inside the widget
XWindowAttributes attr;
#if QT_VERSION >= 0x040000
XGetWindowAttributes(x11Info().display(),winId(),&attr);
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Info().display(),winId(),
attr.your_event_mask & ~SubstructureRedirectMask);
XFlush(x11Info().display());
XSync(x11Info().display(),False);
#else
XGetWindowAttributes(x11Display(),winId(),&attr);
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Display(),winId(),
attr.your_event_mask & ~SubstructureRedirectMask);
XFlush(x11Display());
XSync(x11Display(),False);
#endif
#endif
set_window_attr("border_width",0);
set_check("~father");
// Open a Library window with dummy width and height
// it will be resized soon
open_window(0,0,100,100,(Hlong)winId(),"visible","",&WinID);
set_check("father");
#ifdef Q_WS_X11
// Reset widget attributes to previous settings (see above comment)
#if QT_VERSION >= 0x040000
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Info().display(),winId(),attr.your_event_mask);
#else
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Display(),winId(),attr.your_event_mask);
#endif
#endif
}// Resize the Library window whenever the QLibraryWindow widget is resized
void QLibraryWindow::resizeEvent(QResizeEvent*)
{
using namespace Library;#ifdef Q_WS_X11
// See comment in ::OpenWindow()
XWindowAttributes attr;
#if QT_VERSION >= 0x040000
XGetWindowAttributes(x11Info().display(),winId(),&attr);
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Info().display(),winId(),
attr.your_event_mask & ~SubstructureRedirectMask);
XFlush(x11Info().display());
XSync(x11Info().display(),False);
#else
XGetWindowAttributes(x11Display(),winId(),&attr);
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Display(),winId(),
attr.your_event_mask & ~SubstructureRedirectMask);
XFlush(x11Display());
XSync(x11Display(),False);
#endif
#endif
// Set the Library window to its new size.
set_window_extents(WindowID(),0,0,width(),height());
#ifdef Q_WS_X11
// See comment in ::OpenWindow()
#if QT_VERSION >= 0x040000
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Info().display(),winId(),attr.your_event_mask);
#else
if (attr.your_event_mask & SubstructureRedirectMask)
XSelectInput(x11Display(),winId(),attr.your_event_mask);
#endif
#endif
}@
-
Bump...
Any idea? Maybe my post was not clear...??
-
You might want to explain, why you want to mix three approaches for the frame to be displayed. What is the reason why you want to use QWdiget at all, since you are not using any qt code to get the frame displayed but programmed it yourself again in the resize event?