gtkmm:窗口内的模态小部件
我有以下问题:我创建了一个程序,提示用户进行一些输入。这是使用派生的 Gtk::Dialog
完成的,其使用方式如下:
if (modal_dialog->run() == SUCCESS){
// do stuff depending on modal_dialog inputs here
}
现在,我想用主窗口中显示的嵌入式小部件替换对话框,但其作用就像我的模式一样对话。这意味着我希望能够调用类似的内容:
if (modal_widget->run == SUCSESS){
// hide modal widget and do stuff
}
这在 C++/gtkmm 中很容易实现吗?
注意:我设法使用状态变量等获得所需的行为(对于最终用户来说感觉是一样的)...这意味着,我手动显示
想要的模式小部件,并告诉wannabe-modal小部件中的确认按钮执行其余的例程(上面的if
语句的主体)。然而,我对不同的操作使用相同的wannabe-modal小部件,这样我就必须始终跟踪我正在做的事情,这不是很优雅。
I have the following issue: I created a program which prompts the user for some input. This is done using a derived Gtk::Dialog
that is used like follows:
if (modal_dialog->run() == SUCCESS){
// do stuff depending on modal_dialog inputs here
}
Now, I would like to replace the dialog by an embedded widget that is shown within my main window, but acts just like my modal dialog. This means I would like to be able to call something like:
if (modal_widget->run == SUCSESS){
// hide modal widget and do stuff
}
Is this easily possible in C++/gtkmm?
Note: I managed to get the desired behaviour (it feels the same for the end user) using state variables etc... This means, I manually show
the wannabe-modal widget, and tell the confirmation button within the wannabe-modal widget to do the rest of the routine (body of the above if
-statements). However, I'm using the same wannabe-modal widget for different actions, so that I have always to keep track of what I'm doing, which is not very elegant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个本地循环对象并进行嵌套循环,而不是调用
run()
。我不太了解 gtkmm,但 gtk+ 代码是:现在,在确定/取消按钮的
clicked
事件中,只需调用g_main_loop_quit(loop)
并嵌套循环将会中断。实际上,这或多或少就是 gtk_dialog_run 函数的作用。
但要小心!您的小部件
run()
是阻塞的,但不是模态的,这是一个危险的野兽:应用程序中的任何其他小部件仍将对用户负责。您可以自行决定是否避免任何意外的重新进入。Instead of calling
run()
You can create a local loop object and make a nested loop. I don't know gtkmm very well, but the gtk+ code would be:Now, in the
clicked
event of your Ok/Cancel buttons simply callg_main_loop_quit(loop)
and the nested loop will break.Actually this is, more or less, what the
gtk_dialog_run
function does.But beware! Your widget
run()
is blocking but not modal, and this is a dangerous beast: any other widget in the application will still be responsible to the user. It is up to you to avoid any undesired reentry.