禁用 gtkbutton 的发光效果

发布于 2024-10-21 01:34:47 字数 56 浏览 5 评论 0原文

我想知道如何禁用鼠标悬停时 gtkButton 的发光效果。 请帮我。

先感谢您。

I would like to know that how to disable the glow effect of gtkButton on mouseover.
Please help me.

Thank you in advance.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖乖哒 2024-10-28 01:34:47

这可能就是您正在寻找的。它是 C++,但希望您可以将其翻译为等效的 Python。该代码会更改不同状态下小部件的背景颜色。

void changeColor(Gtk::Widget* widget, double r, double g, double b) {
    Glib::RefPtr<Gdk::Colormap> colormap = widget->get_colormap();
    Glib::RefPtr<Gtk::Style> style = widget->get_style()->copy();

    // STATE_NORMAL (most of the time)
    {
        Gdk::Color color;
        color.set_rgb_p(r,g,b);         // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_NORMAL, color);
    }

    // STATE_PRELIGHT (when mouse hovers)
    {
        Gdk::Color color;
        color.set_rgb_p(r*0.9,g*0.9,b*0.9); // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_PRELIGHT, color);
    }

    // STATE_ACTIVE (when clicked)
    {
        Gdk::Color color;
        color.set_rgb_p(r*0.8,g*0.8,b*0.8); // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_ACTIVE, color);
    }

    widget->set_style(style);
}

您有兴趣在 STATE_PRELIGHT 块中设置正确的颜色,以便它们与 STATE_NORMAL 块中的颜色相同。 (我猜这就是你问题的意思)。

顺便说一句,还有另外两个状态在上面的方法中没有处理:STATE_SELECTED 和 STATE_INSENSITIVE。还必须指出的是,该函数尽管有其名称,但实际上并不会更改任何小部件的颜色。例如,它不会更改标签的颜色,因为标签采用其容器的颜色。所以不要太认真地对待函数签名。

This may be what you are looking for. It is c++, but hopefully you can translate it to the python equivalent. The code changes the background color of a widget in different states.

void changeColor(Gtk::Widget* widget, double r, double g, double b) {
    Glib::RefPtr<Gdk::Colormap> colormap = widget->get_colormap();
    Glib::RefPtr<Gtk::Style> style = widget->get_style()->copy();

    // STATE_NORMAL (most of the time)
    {
        Gdk::Color color;
        color.set_rgb_p(r,g,b);         // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_NORMAL, color);
    }

    // STATE_PRELIGHT (when mouse hovers)
    {
        Gdk::Color color;
        color.set_rgb_p(r*0.9,g*0.9,b*0.9); // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_PRELIGHT, color);
    }

    // STATE_ACTIVE (when clicked)
    {
        Gdk::Color color;
        color.set_rgb_p(r*0.8,g*0.8,b*0.8); // <-- customize this
        colormap->alloc_color(color);
        style->set_bg(Gtk::STATE_ACTIVE, color);
    }

    widget->set_style(style);
}

You are interested in setting the right colors in the STATE_PRELIGHT block so that they are the same than in the STATE_NORMAL block. (I'm guessing this is what you mean with your question).

By the way, there are two other states which are not handled in the method above: STATE_SELECTED and STATE_INSENSITIVE. It must also be stated that this function, despite its name, doesn´t actually change the color of any widget. It won't change the color of a label, for example, since a label takes the color of it's container. So don't take the function signature too seriously.

奢欲 2024-10-28 01:34:47

以下Python代码将复制按钮的样式,将gtk.STATE_PRELIGHT(鼠标悬停)状态下的背景颜色设置为与gtk.STATE_NORMAL相同的颜色,并然后将样式设置回小部件上。

import gtk

window = gtk.Dialog()
button = gtk.Button('Click Me')

style = button.get_style().copy()
style.bg[gtk.STATE_PRELIGHT] = style.bg[gtk.STATE_NORMAL]
button.set_style(style)

window.vbox.pack_start(button)
window.show_all()
window.run()

由于这不会干扰按钮的实际状态,因此对其余代码没有副作用。

此代码可能会对 GDK 主题产生影响。如果我发现一个主题安全的方法,我将编辑我的答案。

The following Python code will make a copy of the button's style, set the background color in the gtk.STATE_PRELIGHT (mouseover) state to the same color as gtk.STATE_NORMAL, and then set the style back on the widget.

import gtk

window = gtk.Dialog()
button = gtk.Button('Click Me')

style = button.get_style().copy()
style.bg[gtk.STATE_PRELIGHT] = style.bg[gtk.STATE_NORMAL]
button.set_style(style)

window.vbox.pack_start(button)
window.show_all()
window.run()

Since this doesn't mess with the actual state of the button, there are no side effects to the rest of your code.

This code MAY have the an affect on GDK themes. If I discover a theme-safe method for this I will edit my answer.

成熟稳重的好男人 2024-10-28 01:34:47
import gtk

def enter(widget, event):
    widget.set_state(gtk.STATE_NORMAL)
    return False

win = gtk.Dialog()
button = gtk.Button('Button')
button.connect_after('enter-notify-event', enter)
win.vbox.pack_start(button, 0, 0)
win.vbox.show_all()
win.run()
import gtk

def enter(widget, event):
    widget.set_state(gtk.STATE_NORMAL)
    return False

win = gtk.Dialog()
button = gtk.Button('Button')
button.connect_after('enter-notify-event', enter)
win.vbox.pack_start(button, 0, 0)
win.vbox.show_all()
win.run()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文