简体   繁体   English

gtkmm-3.0和Cairomm,透明窗口不起作用

[英]Gtkmm-3.0 and Cairomm, transparent window not working

I've been trying for the last hour to make this work. 我已经尝试了最后一个小时才能完成这项工作。 The idea es Dock is a class whose base is Gtk::Window, and upon the signal_draw() being emited, the given context should be painted by CairoMM to be transparent.. Instead I see a black window. es Dock的想法是一个基于Gtk :: Window的类,并且在发出signal_draw()时,CairoMM应该将给定的上下文绘制为透明的。。相反,我看到了一个黑色的窗口。 Here goes the code: 代码如下:

Dock::Dock() : Gtk::Window()
{
    set_decorated(false);
    set_default_size(200,200);  
    set_app_paintable(true);
    signal_draw().connect(sigc::mem_fun(*this,&Dock::dibujar));

}

bool Dock::dibujar(const Cairo::RefPtr<Cairo::Context>& contexto)
{

    contexto->set_source_rgba(1.0,1.0,1.0,0.0);
    contexto->set_operator(Cairo::OPERATOR_SOURCE);
    contexto->paint();
    return false;
}

Shouldn't it be enough to make the window transparent? 使窗口透明不是足够吗?

Your draw handler doesn't have access to the information about what else should be painted on the window, so your paint() call paints a transparent layer above what is, I guess by default, a black background. 您的绘制处理程序无法访问有关在窗口上还要绘制其他内容的信息,因此您的paint()调用将在默认情况下在黑色背景之上绘制透明层。

Luckily there is a method to achieve what you want: Gtk::Widget::set_opacity() 幸运的是,有一种方法可以实现您想要的: Gtk::Widget::set_opacity()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM