Classes - Annotated - Tree - Functions - Home - Structure Qte

Editor Example

This example shows two simple text editors, with most of the program written in Qt. One editor is a Qt QMultiLineEdit, the other is an Athena Widgets text widget. They are bound together in a Qt main window.

#include "qxt.h"
#include <qmainwindow.h>
#include <qmultilineedit.h>
#include <qpainter.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qsplitter.h>
#include <X11/IntrinsicP.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/AsciiText.h>

static const char* QTEDMSG =
    "This is a Qt widget.\nIt is a QMultiLineEdit.";

static const char* XTEDMSG =
    "This is an Xt widget.\nIt is an asciiTextWidgetClass.";

class EncapsulatedXtWidget : public QXtWidget {
    Widget editor;
    EncapsulatedXtWidget(QWidget* parent) :
        QXtWidget( "shell", topLevelShellWidgetClass, parent )
        Arg args[20];
        Cardinal nargs=0;
        XtSetArg(args[nargs], XtNeditType, XawtextEdit); nargs++;
        XtSetArg(args[nargs], XtNstring, XTEDMSG);       nargs++;
        editor = XtCreateWidget( "editor", asciiTextWidgetClass, xtWidget(), args, nargs);
        XtRealizeWidget( editor );
        XtMapWidget( editor );
    void resizeEvent( QResizeEvent* e )
        QXtWidget::resizeEvent( e );
        XtResizeWidget( editor, width(), height(), 2 );

class TwoEditors : public QMainWindow {
    QMultiLineEdit* qtchild;
    EncapsulatedXtWidget* xtchild;

    TwoEditors() :
        QMainWindow( 0, "mainWindow")
        QPopupMenu* file = new QPopupMenu( this );
        file->insertItem("E&xit", qApp, SLOT( quit() ) );
        menuBar()->insertItem( "&File", file );
        QSplitter* splitter = new QSplitter( this );
        splitter->setOpaqueResize( TRUE );
        setCentralWidget( splitter );
        xtchild = new EncapsulatedXtWidget( splitter );
        qtchild = new QMultiLineEdit( splitter );


main(int argc, char** argv)
    QXtApplication app(argc, argv, "TwoEditors");
    TwoEditors m;
    return app.exec();

Copyright © 2005 TrolltechTrademarks
Qt version 2.3.10