返回介绍

Editors in a Qt main window

发布于 2019-10-04 14:58:07 字数 2369 浏览 942 评论 0 收藏 0

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.


Implementation:

#include <qmainwindow.h>
#include <qmultilineedit.h>
#include <qpainter.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qsplitter.h>
#include "qxt.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;
public:
    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;

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);
    }

};

int main(int argc, char** argv)
{
    QXtApplication app(argc, argv, "TwoEditors");
    TwoEditors m;
    app.setMainWidget(&m);
    m.show();
    return app.exec();
}

See also Qt Xt/Motif Support Extension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文