有时GTK模态对话框不是模态---错误或特征? [英] Sometimes GTK modal dialogs are not modal --- bug or feature?

查看:129
本文介绍了有时GTK模态对话框不是模态---错误或特征?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在GTK中创建一个自定义对话框( GTK2或GTK3 )并将其设置为模态时,我的应用程序的其他窗口的所有输入都将被忽略。这几乎总是运行,但它在某些条件下失败。

When I create a custom dialog in GTK (both, GTK2 or GTK3) and set it to be modal, all input to other windows of my application is ignored. This works nearly always, but it fails under certain conditions.

当我将包含TreeView的ScrolledWindow添加到我的对话框时,它仍然按照假定的方式工作。 但是如果我用条目填充TreeView,直到ScrolledWindow开始显示其滚动条---模式突然丢失,我可以点击我的其他窗口!

When I add a ScrolledWindow containing a TreeView to my dialog, it still works as supposed. But if I fill the TreeView with entries until the ScrolledWindow starts to display its scroll bars --- the modality is suddenly lost and I can click on my other windows!

这是我能够设置的最基本的例子。它是用Vala编写的,但你会明白:

Here is the most basic example I was able to set up. It's written in Vala, but you'll get the idea:

class MyDialog: Gtk.Dialog {

    public MyDialog() {
        this.modal = true;

        var data = new Gtk.ListStore(1, typeof(string)); 

        // increase this number -- the dialog is not modal anymore!
        for (int i=0; i<2; ++i) {
            Gtk.TreeIter current;
            data.append(out current);
            data.set(current, 0, "Lorem Ipsum"); 
        }

        var render = new Gtk.CellRendererText();

        var column = new Gtk.TreeViewColumn();
            column.pack_start(render, true);
            column.add_attribute(render, "text", 0);

        var treeview = new Gtk.TreeView.with_model(data);
            treeview.append_column(column);
            treeview.show();

        var scroll = new Gtk.ScrolledWindow(null, null);
            scroll.set_size_request(100, 100);
            scroll.add(treeview);
            scroll.show();

        (this.get_content_area() as Gtk.Box).add(scroll);
    }
}

int main (string[] args) {
    Gtk.init (ref args);

    var window = new Gtk.Window();

    window.set_default_size(350, 170);
    window.destroy.connect(Gtk.main_quit);

    var button = new Gtk.Button.with_label("Click me!");
    button.clicked.connect(() => {
        var dialog = new MyDialog();
        dialog.set_transient_for(window);
        dialog.run();
        dialog.destroy();
    });

    window.add(button);
    window.show_all();

    Gtk.main();
    return 0;
}

使用以下内容编译它:

Compile it with:

valac --pkg gtk+-3.0 main.vala

我错过了什么?这是行为吗?或者它是一个错误?如果是这样,是否有解决方法?

Am I missing something? Is this behaviour wanted? Or is it a bug? If so, is there a workaround?

编辑:我调查了一点:当Ubuntu的覆盖滚动条被卸载时,问题消失。所以它还没有解决,但我知道我必须报告这一点...

I investigated a bit further: The problem disappears when the overlay-scrollbars from Ubuntu are uninstalled. So It's not solved yet, but I know where I have to report this...

推荐答案

肯定是一个错误。发布错误报告和/或升级您的GTK +库。

Definitely a bug. Post a bug report and/or upgrade your GTK+ lib.

这篇关于有时GTK模态对话框不是模态---错误或特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆