Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将任何矩形绘制到GTK+;DrawingArea填充整个DrawingArea_C++_C_Gtk_Gtkmm_Cairo - Fatal编程技术网

C++ 将任何矩形绘制到GTK+;DrawingArea填充整个DrawingArea

C++ 将任何矩形绘制到GTK+;DrawingArea填充整个DrawingArea,c++,c,gtk,gtkmm,cairo,C++,C,Gtk,Gtkmm,Cairo,我有一个GTK+绘图区域,应该在左上角显示一个矩形。当我使用Cairo绘制矩形时,整个绘图区域都用矩形的颜色填充。我怎样才能防止呢?开罗为什么这样做?我做错了什么 #include <gtkmm.h> class Window : public Gtk::Window { private: Gtk::DrawingArea area; bool on_area_expose(GdkEventExpose* event) { Gtk::All

我有一个GTK+绘图区域,应该在左上角显示一个矩形。当我使用Cairo绘制矩形时,整个绘图区域都用矩形的颜色填充。我怎样才能防止呢?开罗为什么这样做?我做错了什么

#include <gtkmm.h>

class Window : public Gtk::Window
{
  private:
    Gtk::DrawingArea area;

    bool on_area_expose(GdkEventExpose* event)
    {
      Gtk::Allocation allocation = area.get_allocation();
      Cairo::RefPtr<Cairo::Context> context =
          area.get_window()->create_cairo_context();
      int width = allocation.get_width();
      int height = allocation.get_height();
      context->set_source_rgba(0, 0, 0, 1);
      context->rectangle(0, 0, double(width)/10, double(height)/10);
      context->paint();
      return true;
    }

  public:
    Window() : Gtk::Window()
    {
      area.signal_expose_event().connect(
        sigc::mem_fun(*this, &Window::on_area_expose));
      add(area);
    }
};

int main(int argc, char* argv[])
{
  Gtk::Main app(argc, argv);
  Window window;
  window.show_all();
  Gtk::Main::run(window);
  return 0;
}
在当前剪辑区域内的任何位置绘制当前源。正确的调用方法是

g++ gtktest.cpp `pkg-config --libs --cflags gtkmm-2.4` -o gtktest