问题描述
(这是我的第一篇文章,对不起,如果我做错了...)
(This is my first post, sorry if I do something wrong...)
我正在Vala编写一个程序,可以用来设计教室。
我决定将GTK用于GUI(Vala与该控件集成得很好),
和开罗绘制教室图(GTK默认随附此控件)。
I am writing a program in Vala with which one can design a classroom.I have decided to use GTK for the GUI (Vala integrates well with this),and Cairo to draw the classroom diagram (GTK comes with this by default).
我创建了一个教室类(Gtk.DrawingArea的子类),
当前应该仅显示一个正方形:
I have created a 'classroom' class (a subclass of Gtk.DrawingArea),which currently should just display a square:
c >小部件,将其放入 Gtk.Grid ,这是我选择的布局小部件。
编译代码并运行它时,出现一个空白窗口:I put my classroom widget into a Gtk.Grid, my layout widget of choice. When I compile my code and run it, I get a blank window:
但是,如果我不使用 Gtk.Grid ,只需添加我的教室使用 root.add()(我已将其注释掉),正确显示教室小部件:
However, if I do not use Gtk.Grid, and just add my classroom using root.add() (which I have commented out), the classroom widget is displayed correctly:
为什么我的小部件
我该怎么解决?
推荐答案
问题在于单元格的大小为0x0像素,因为网格不知道绘图区域实际需要多少空间。
The problem is that the cell is sized 0x0 pixels, because the grid doesn't know how much space your drawing area actually needs.
一个简单的解决方案是只请求一些固定的请调整大小,试试:
A simple solution is to just request some fixed size, try this:
var classroom = new Classroom(); classroom.set_size_request (40, 40);PS:我是通过查看SO上的其他类似问题,特别是。
PS: I got this idea by looking at other similar questions on SO, particularly this one.
这篇关于附加到Gtk.Grid时Gtk.DrawingArea为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!