Use other graphics libraries in the QT program

xiaoxiao2021-03-05  28

Yu Xi QT is a very perfect graphic library under the X window system, before this, OSF / MotiF once is a dominant high-level graphics library, and forms a commercial standard. The general desktop environment on some commercial UNIX systems is based on Motif, and software Java, Netscape, and so on use Motif. Make some early programs to be a more interested topic in QT. GTK, as another set of graphics libraries with QT, deeply loved by C programmers. Use Qt and GTK in the same program, even other graphics libraries, it is very meaningful for writing embedded (Embeded) programs. This also official this article described herein. 1. Conceptual embedded program of embedded programs generally does not have its own primary cyclic body, which uses the window ID to embed other windows. At the XLIB level, use the function XReparentWindow to reset the parent window of a window: XReparentWindow (Display * Display, Window W, Window Parent, INT X, INT Y) can embed the window W into the window Parent. The embedded program typically uses a dynamic library-loaded method, so that the graphics library under any X-window system can work with other libraries and other libraries. The embedded program requires a parent window to manage some of the operations of the window, such as the size management of the window, keyboard focus, and more. A complete application can also be embedded in other windows, in general, make the window not managed when establishing a main window, and then set the parent window using XReparentWindow (). 2. Using Motif in QT in QT 2.x has an extension of qt XT / Motif, which allows users to write a program that supports XT / Motif and Qt. Qt The extension of XT / Motif is the establishment of class qxtwidget and class qxtapplication, which mainly handles the underlying event of embedded windows.

Building a program that is mainly included in QT, as long as you use QXTApplication to establish a main program, set a main window that can contain QT and Motif windows, for example: QXTApplication APP (Argc, Argv, "TwoEditors") TwoEditors M; App.SETMAINWIDGET (& M); M.Show (); return app.exec (); set two windows in m, one is established by Qt class, one is created by QXTWidget class, Class Twoeditors: public QMainWindow {QMultiLineEdit * qtchild; EncapsulatedXtWidget * xtchild; public: TwoEditors (): QMainWindow (0, "mainWindow") {QPopupMenu * file = new QPopupMenu (this); file-> insertItem ( "E & xit", qApp, SLOT (quit ( ))); menuBar () -> insertItem ( "& File", file); statusBar (); QSplitter * splitter = new QSplitter (this); splitter-> setOpaqueResize (TRUE); setCentralWidget (splitter); xtchild = new EncapsulatedXtWidget ( Splitter; Qtchild = new qmultilineEdit (splitter); Qtchild-> setText (QTedMSG);}}; 3. Use GTK in QT to use GTK in QT to use GTK slightly more complex, mainly because of the main loop of QT and GTK The main loop is more complicated together. In the package QGTKWIDGET, the author uses a part of the GTK part of the code, part of the code of Qt and part of the KDE, constructed the QGTKWIDGET class and the QGTKApplication class.

The structure of the program is similar to the above example, QGTKApplication A (Argc, Argv); qmainwindow * wnd = new mainwnd (); qpushbutton * Qt = new qpushbutton ("this is qt!", WND); QGTKWIDGET * GTK = New QGTKWIDGET (WND); WND-> Resize (200, 100); QT-> setGeometry; gtk-> setGeometry (100, 0, 100, 100); gtkwidget * box = gtk_vbox_new (false, 0); gtk_container_add (gtk_container (GTK) -> getGtkWidget ()), box); GtkWidget * b = gtk_button_new_with_label ( "This is GTK!"); gtk_box_pack_start (GTK_BOX (box), b, TRUE, TRUE, 0); gtk_widget_show (b); gtk_widget_show (box); Wnd-> show (); a.setmainwidget (WND); gtk_widget_show (b); gtk_widget_show (box); Return a.exec (); Reference: QT-2.x Example: http://www.troll .no / qgtkwidget: http://freshmeat.net/Projects/qgtkwidget/ Excerpt: IBM DeveloperWorks China website

转载请注明原文地址:https://www.9cbs.com/read-34242.html

New Post(0)