【问题标题】:How to add an image to a button with GTK4?如何使用 GTK4 将图像添加到按钮?
【发布时间】:2021-01-17 18:25:00
【问题描述】:

我知道这个问题存在 How to add an image to a button with GTKgtk_button_set_image 在 gtk4 中已弃用。

【问题讨论】:

  • 只需创建一个GtkImageadd()Button。我认为的一点是,当用户只需设置他们想要的孩子并将其添加进去时,不需要由Button 本身创建子小部件的专门代码。
  • 好的,我明白了。我只需要像这样设置它:gtk_button_set_child (GTK_BUTTON (button), image); 其中按钮是 GtkButton,图像是 GtkImage。谢谢 。那很快。
  • gtk_container_add (GTK_CONTAINER (button), image) imo 更好,只是看起来更正确。
  • gtk_container_add() 在 gtk4 中也被弃用了
  • 好的,那就用gtk_button_set_child()

标签: c user-interface gtk


【解决方案1】:

gtk_button_set_child (GTK_BUTTON (button), image); 其中 button 和 image 分别是 GtkButton 和 GtkImage 。

【讨论】:

    【解决方案2】:
    Gtk.Box box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 5);
    box.prepend(new Image.from_icon_name("media-playback-start"));
    box.append(new Gtk.Label("Play"));
    button.child = box;
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    猜你喜欢
    • 2017-08-21
    • 2020-08-24
    • 2018-02-05
    • 2020-05-04
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多