我有一个编译和工作程序,但我不知道如何将按钮放在左上角以外的任何地方。
我需要在 rowcol 中指定位置(就像我现在这样),还是在使用 XtCreateManagedWidget 分配每个按钮时指定它们的位置?
请注意,我声明了回调,但我没有包括它们,因为它们正在工作。
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/ToggleB.h>
#include <Xm/RowColumn.h>
int main(int argc, char **argv)
{
Widget shell, rowcol, toggle1, toggle2;
XtAppContext app;
//Set the window's size at 300x300
shell = XtVaAppInitialize(&app, "Radio", NULL, 0, &argc, argv, NULL,
XmNwidth, 300, XmNheight, 300, NULL);
//I want the buttons to start at 100x100
rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, shell,
XmNx, 100, XmNy, 100, NULL);
XtManageChild(rowcol);
//Add the buttons & callbacks
toggle1 = XtCreateManagedWidget("Switch1", xmToggleButtonWidgetClass, rowcol, NULL, 0);
XtAddCallback(toggle1, XmNvalueChangedCallback, toggle1_cbk, NULL);
toggle2 = XtCreateManagedWidget("Switch2", xmToggleButtonWidgetClass, rowcol, NULL, 0);
XtAddCallback(toggle2, XmNvalueChangedCallback, toggle2_cbk, NULL);
//Starts everything up
XtRealizeWidget(shell);
XtMainAppLoop(app);
return 0;
}
最佳答案
将您的小部件放入公告板。
frame = XtVaCreateWidget("frame", xmBulletinBoardWidgetClass, shell,
XmNwidth, 300, XmNheight, 300, NULL);
rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, frame,
XmNx, 100, XmNy, 100, NULL);
XtManageChild(frame);
XtManageChild(rowcol);
shell 的直接子级是特殊的。设置它的 X 和 Y 不会将子元素定位在 shell 中,而是定位到 shell 本身。此外,许多小部件会忽略其子项的 X 和 Y 位置。但是 BulletinBoard 没有。
来自 Motif 手册:
BulletinBoard is a general-purpose manager that allows children to be placed at arbitrary x, y positions.
关于c++ - 如何在主题中定位切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25433710/