Application Development in Linux: Use the graphics library in QT

Source: Internet
Author: User
Tags gtk
Article Title: Application Development in Linux: Use the graphics library in QT. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
GTK, as another set of graphics libraries that coexist with QT, is favored by C programmers. Using QT, GTK, and even other graphics libraries in the same program makes sense for writing embedded (Embeded) programs. This is also the subject of this article.
  
   1. Concepts of embedded programs
Embedded programs generally do not have their own main loop bodies. They directly use the window ID to embed them into other windows. At the Xlib level, use the XReparentWindow function to reset the parent window of a window:
  
XReparentWindow (Display * display, Window w,
Window parent, int x, int y)
  
The window w can be embedded in the window parent.
  
Embedded programs generally use the dynamic library loading method, so that any graphics library in the X Window System can work together with other libraries through the output (Export) method of its window ID. The embedded program requires a parent window to manage window operations, such as window size management and keyboard focus. A complete application can also be embedded in other windows. Generally, the window is not managed when the main window is created, and then the parent window is set using XReparentWindow.
  
   2. Use Motif in QT
In QT 2.x, there is a QT Xt/Motif extension, which enables users to write programs that support both Xt/Motif and Qt. QT has established QXtWidget and QXtApplication class for Xt/Motif extensions. It mainly handles underlying events of Embedded Windows.
  
Create a program containing the Motif component (Widget) based on QT. You only need to use QXtApplication to create the main program and set a main window that can contain the QT and Motif windows. For example:
  
QXtApplication app (argc, argv, "TwoEditors ");
TwoEditors m;
App. setMainWidget (& m );
M. show ();
Return app.exe c ();
  
Set two windows in m, one created by the QT class and the other created by the 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
The use of GTK in QT is a little complicated, mainly because it is complicated to combine the main cycle of QT and the main cycle of GTK. In the package QGtkWidget, the author uses some GTK Code, some QT code and some KDE code to construct the QGtkWidget class and QGtkApplication class.
  
The structure of the program is similar to the preceding example,
  
QGtkApplication a (argc, argv );
QMainWindow * wnd = new MainWnd ();
QPushButton * Qt = new QPushButton ("This is Qt! ", Wnd );
QGtkWidget * Gtk = new QGtkWidget (wnd );
Wnd-> resize (1, 200,100 );
Qt-> setGeometry );
Gtk-> setGeometry (100,100, 0 );
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.exe c ();
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.