- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个 GtkWidget 类型的 10x20 数组。我想让它们每个都成为一个 GtkEventBox,我将在其中附加一个标签。
我应该如何创建和使用 2D GtkWidget* 数组?
这是我迄今为止尝试过的:
//global variable:
GtkWidget *labelPlate[ROWS][COLUMNS];
...
...
inside the function that creates the table and attaches the event boxes to it
//my table, where the EventBoxes will be attached to
GtkWidget *finalPlateTable = gtk_table_new (10, 20, TRUE);
int i, j;
for(i = 0; i<ROWS; i++){
for(j=0 ; j<COLUMNS; j++){
//Make a char with the current float and create a label with it.
char finalString[14];
sprintf(finalString, "%.2f", plate[i][j]);
GtkWidget *label = gtk_label_new(finalString);;
//Labels cannot have bg color, so attach each label to an event box
/*HERE I GET SEG FAULT*/
labelPlate[i][j]=gtk_event_box_new();
//adding the label to my eventbox
gtk_container_add(GTK_CONTAINER(labelPlate[i][j]), label);
//Add the corresponding bg color to each event box
GdkColor color;
switch(scalePlate[i][j]){
...
...
break;
}
//coloring the event box with the corresponding background
gtk_widget_modify_bg ( GTK_WIDGET(labelPlate[i][j]), GTK_STATE_NORMAL, &color);
//attach the event box to the appropriate location of my table
gtk_table_attach_defaults (GTK_TABLE (finalPlateTable), labelPlate[i][j], j, j+1, i, i+1);
//show them!
gtk_widget_show(label);
gtk_widget_realize(labelPlate[i][j]);
}
}
//adding the table to my vertical box, and show both of them
gtk_box_pack_start(GTK_BOX (verticalBox), finalPlateTable, TRUE, TRUE, 10);
gtk_widget_show (finalPlateTable);
gtk_widget_show (verticalBox);
我想指出,我对C相当陌生,而且我不知道如何使用malloc
(但我怀疑我应该利用它,现在)。
最佳答案
我找到了解决方案:
将数组初始化为:
GtkWidget **myarray;
myarray = g_new(GtkWidget *, ROWS*COLUMNS);
然后使用以下函数访问特定的行和列:
int returnPosAt(int row, int column){
return row*COLUMNS+column;
}
那么,你可以打电话
myarray[returnPosAt(i, j)]=gtk_event_box_new();
所以,实际上你有一个 1D 数组,通过调用该函数,你可以获得 2D 位置 (i, j) 的相应 1D pos。
关于创建 2D GtkWidget 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728096/
我有以下代码,我正在努力将标签对齐在中心它的父级(布局),但对我来说没有任何作用: int main(int argc, char ** argv){ GtkWidget *window;
抱歉,我是 Gtk 的新手,所以这可能是个愚蠢的问题。 我使用 Gtk+ 3.0 并有这个代码 GtkWidget *widget; widget=gtk_box_new(GTK_ORIENTATIO
是否可以创建 gtkwidgets 的多维数组?具体是这样的: mywidgetlist[2]["title"]; 或者我应该以不同的方式来做这件事?我该怎么做? 基本上,我有许多由较小的小部件组成的
我问为什么如果我决定调用另一个文件中的函数,返回的 GtkWidget* 如果使用的话会导致段错误(强制转换,如示例中的 gtk 函数,...) 在 main 中,我运行 gtk_init 并从另一个
我一直在摸不着头脑,为什么下面的代码会触发绘制回调三次而不是一次。 #include #include using namespace std; void on_draw(){ cout
我有一个 GtkImage,我正在使用 GdkPixbuf 进行操作。当我更改它时,我需要重新绘制它才能使更改生效。现在我通过隐藏然后显示图像来做到这一点。这样做的正确方法是什么? 最佳答案 gtk_
我需要能够以编程方式探索 GTK GUI 的结构。我有 GtkWidget,我想找到该小部件的任何子部件。现在我知道 GtkContainer 有一个查找子级的功能,并且 GtkContainer 是
如何在 GtkWidget 中设置前导空格?正如您在下面的图像中看到的那样,用户名/密码小部件在窗口开始时离水平线有点远 我的代码: GtkWidget *window; GtkWidget
如何在 GtkWidget 中设置前导空格?正如您在下面的图像中看到的那样,用户名/密码小部件在窗口开始时离水平线有点远 我的代码: GtkWidget *window; GtkWidget
我想创建一个 GtkWidget 类型的 10x20 数组。我想让它们每个都成为一个 GtkEventBox,我将在其中附加一个标签。 我应该如何创建和使用 2D GtkWidget* 数组? 这是我
我有一个应用程序,它基本上在终端模式下运行,但它可以在另一个线程中打开它的 GUI 部分(带有 GtkTextView 的简单窗口来打印一些消息)。当主线程中发生某些事件时,我需要手动更新此 GtkT
我想复制一个通过 GtkBuilder 加载的 GtkWidget 我的问题是告诉 Gtk 将它打包到它已经存在的同一个 vbox 中会导致错误,而且我不知道如何复制它。我想这涉及到指针和引用的困惑,
我有一个函数连接到 gtk 中组合框的“已更改”信号,它又调用另一个函数 read_button_config。 read_button_config 采用主窗口、一个组合框和一个我没有全局声明的 v
我需要编写一个回调来更改存储在 GtkWidget 数组中的标签的字体颜色。 当前状态的代码在这里 https://github.com/dustynine/colta-gtk/blob/struct
我想知道是否有一种方法可以动态地“发送到后面”或“移到前面”GtkWidget。 (我知道,可以通过更改 GtkWidget 的创建顺序来完成) 示例:(GTK+ 2.0、Cent OS 7.0、C)
我正在尝试编写一个包含 GtkBox(水平)的应用程序,我根据各种条件在其中添加动态数量的按钮(带有标签)。现在我想防止 GtkBox 增长超过(例如)600px。按钮标签可以是椭圆形的。 所以我的问
我正在用 C 编写 Gtk+3 应用程序。 用户界面是用 glade 构建的。 我创建了一个独立的 GtkBox,它应该在我的应用程序的多个地方使用。当我尝试多次使用 GtkBox 时,出现以下错误:
在大多数 pygtk 小部件页面中,它们包含称为“Attributes”、“Properties”和“Style Properties”的部分。如何更改这些特性和特性? 最佳答案 可以通过三种方式改变
是否可以将私有(private)数据添加到GtkWidget? 背景: 我有很多 GtkCheckBotton,所有这些小部件都连接到同一个回调。在回调中,我想处理小部件私有(private)数据(或
我见过的任何例子似乎都是在 GtkWidget 中嵌入 ClutterStage。 链接: http://www.openismus.com/documents/clutter_tutorial/1.
我是一名优秀的程序员,十分优秀!