Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Quick custom control (window to display images)
Forum Updated to NodeBB v4.3 + New Features

Qt Quick custom control (window to display images)

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eren76
    wrote on last edited by
    #1

    Hi,
    I'm developing a software using C# and a third party library written in C which includes wrapper DLLs for C++, and .Net.
    This library can target multiple OSs, and makes use of a "window" from the underlying window manager to to display images and some graphics through a set of display operators.

    The library provides a .Net WinForm control to allow the placement of one or more of this display windows in the UI, or it is also possible just to open a floating window (from the underlying window manager).

    An example on how to build a QT custom widget to implement this window control in a QWidget based application is provided. But I wish I could port my software to QT and make use of QTQuick as user interface, because the application is intended for industrial use and it requires an easy and touch enabled UI.

    So I'm asking if you think it will be possible to easily build a QT Quick control that will allow to place those windows in a Qt Quick UI, and then access the WindowIDs from C++ toin order to use the display operators of the library.

    Here is the example code for the QTWidget:

    @
    // QLibWindow.cpp : Implementation of the class QLibWindow
    //

    #include "qLibwindow.h"

    #ifdef Q_WS_X11
    #if QT_VERSION >= 0x040000
    #include <QX11Info>
    #endif
    #include <X11/Xlib.h>
    #endif

    QLibWindow::QLibWindow(QWidget *parent, long Width, long Height)
    : QWidget(parent)
    {
    resize(Width,Height);
    show();
    OpenWindow();
    }

    QLibWindow::~QLibWindow(void)
    {
    using namespace LibCpp;

    CloseWindow(WindowID());
    }

    // Open a Lib window inside the QLibWindow widget
    void QLibWindow::OpenWindow(void)
    {
    using namespace LibCpp;

    #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 Lib 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
    SetWindowAttr("border_width",0);
    SetCheck("~father");
    // Open a Lib window with dummy width and height
    // it will be resized soon
    LibCpp::OpenWindow(0,0,100,100,(Hlong)winId(),"visible","",&WinID);
    SetCheck("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 Lib window whenever the QLibWindow widget is resized
    void QLibWindow::resizeEvent(QResizeEvent*)
    {
    using namespace LibCpp;

    #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 Lib window to its new size.
    SetWindowExtents(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
    }
    @

    If anyone could help me with code, or is interested id developing an example for me, I would be glad.

    Thanks for any help!

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eren76
      wrote on last edited by
      #2

      This is where the widtget is used:

      @
      // Lib/Qt measure example
      //

      // matching.cpp : Implementation of the class Matching
      //

      #include "matching.h"

      #ifdef Q_WS_X11
      #include <X11/Xlib.h>
      #endif
      #include <qfont.h>
      #include <qlayout.h>
      #include <qstring.h>
      #include <qcursor.h>

      // Constructor: create GUI
      Matching::Matching(QWidget *parent)
      : QWidget(parent)
      {
      WindowIDBuf = -1;
      ...

      // Disp: Father widget for Lib window in HBoxDispAndButtons
      Disp = new QLibWindow(this);
      Disp->setMinimumSize(50,50);

      // Buttons in HBoxDispAndButtons
      QVBoxLayout *Buttons = new QVBoxLayout;

      ...
      }

      // The destructor is called when the user closes the application by clicking
      // on the close button in the window manager decoration.
      Matching::~Matching(void)
      {
      using namespace LibCpp;

      // Close all allocated Lib resources.
      CloseWindow(WindowIDBuf);
      killTimer(Timer);
      }

      // Initialize Lib windows
      void Matching::InitWin(void)
      {
      using namespace LibCpp;

      // Initialize framegrabber
      InitFg();

      WindowWidth = Disp->width();
      WindowHeight = Disp->height();

      // Open a Lib buffer window that will be used to program a flicker-free
      // display of the results.
      OpenWindow(0,0,WindowWidth,WindowHeight,0,"buffer","",&WindowIDBuf);
      SetPart(Disp->WindowID(),0,0,Height-1,Width-1);
      SetPart(WindowIDBuf,0,0,Height-1,Width-1);
      SetLineWidth(Disp->WindowID(),3);
      SetLineWidth(WindowIDBuf,3);
      DispObj(Image,Disp->WindowID());
      }

      // This slot is called whenever the application's main widget is resized.
      // The member function QLibWindow::resizeEvent() of the QLibWindow
      // widget is called before this function, thus only the buffer window needs
      // to be resized at this point.
      void Matching::resizeEvent(QResizeEvent*)
      {
      using namespace LibCpp;

      if (WindowIDBuf>0)
      {
      // Determine the new dimensions of the QLibWindow widget.
      // We save the new dimensions for later use in CopyRectangle.
      WindowWidth = Disp->width();
      WindowHeight = Disp->height();
      SetWindowExtents(WindowIDBuf,0,0,WindowWidth,WindowHeight);
      // Display the current image. Note that this will slow down the resize
      // operation considerably.
      DispObj(Image,Disp->WindowID());
      }
      }

      // This function is called continously after Timer is started in ::Start()
      void Matching::timerEvent(QTimerEvent*)
      {
      StartMatching();
      }

      // Start continuous matching
      void Matching::Start(void)
      {
      StartButton->setEnabled(false);
      StopButton->setEnabled(true);
      // Start Timer -> ::timerEvent() is called continously
      Timer = startTimer(20);
      }

      // Stop continuous matching
      void Matching::Stop(void)
      {
      StartButton->setEnabled(true);
      StopButton->setEnabled(false);
      // Kill Timer
      killTimer(Timer);
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved