返回介绍

Editors in a Motif form

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

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


Implementation:

#include "qxt.h"
#include <qmultilineedit.h>
#include <qpainter.h>
#include <qmessagebox.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <Xm/Form.h>
#include <Xm/Text.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 xmTextWidgetClass.";


class EncapsulatedQtWidget : public QXtWidget {
    QMultiLineEdit* mle;
public:
    EncapsulatedQtWidget(Widget parent) :
        QXtWidget("editor", parent, TRUE)
    {
        mle = new QMultiLineEdit(this);
        mle->setText(QTEDMSG);
    }

    void resizeEvent(QResizeEvent*)
    {
        mle->resize(width(),height());
    }
};

int main(int argc, char** argv)
{
    XtAppContext app;

    Widget toplevel = XtAppInitialize(
        &app, "Editors",
        0, 0, &argc, argv, 0, 0, 0);
    QXtApplication qapp(XtDisplay(toplevel));

    Widget form = XtVaCreateManagedWidget("form",
                    xmFormWidgetClass, toplevel, 0);

    EncapsulatedQtWidget qtchild(form);

    const int marg=10;

    Arg args[20];
    Cardinal nargs=0;
    XtSetArg(args[nargs], XmNwidth, 200);                      nargs++;
    XtSetArg(args[nargs], XmNheight, 200);                     nargs++;
    XtSetArg(args[nargs], XmNleftOffset, marg);                nargs++;
    XtSetArg(args[nargs], XmNtopOffset, marg);                 nargs++;
    XtSetArg(args[nargs], XmNbottomOffset, marg);              nargs++;
    XtSetArg(args[nargs], XmNtopAttachment, XmATTACH_FORM);    nargs++;
    XtSetArg(args[nargs], XmNbottomAttachment, XmATTACH_FORM); nargs++;
    XtSetArg(args[nargs], XmNleftAttachment, XmATTACH_FORM);   nargs++;
    XtSetValues(qtchild.xtWidget(), args, nargs);

    nargs=0;
    XtSetArg(args[nargs], XmNeditMode, XmMULTI_LINE_EDIT);     nargs++;
    XtSetArg(args[nargs], XmNvalue, XTEDMSG);                  nargs++;
    XtSetArg(args[nargs], XmNwidth, 200);                      nargs++;
    XtSetArg(args[nargs], XmNheight, 200);                     nargs++;
    XtSetArg(args[nargs], XmNtopOffset, marg);                 nargs++;
    XtSetArg(args[nargs], XmNbottomOffset, marg);              nargs++;
    XtSetArg(args[nargs], XmNrightOffset, marg);               nargs++;
    XtSetArg(args[nargs], XmNtopAttachment, XmATTACH_FORM);    nargs++;
    XtSetArg(args[nargs], XmNbottomAttachment, XmATTACH_FORM); nargs++;
    XtSetArg(args[nargs], XmNrightAttachment, XmATTACH_FORM);  nargs++;
    XtSetArg(args[nargs], XmNleftAttachment, XmATTACH_WIDGET); nargs++;
    XtSetArg(args[nargs], XmNleftWidget, qtchild.xtWidget());  nargs++;
    Widget xtchild = XtCreateManagedWidget("editor", xmTextWidgetClass,
        form, args, nargs);

    XtRealizeWidget(toplevel);
    XtAppMainLoop(app);
}

See also Qt Xt/Motif Support Extension.

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

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

发布评论

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