2017-02-27 5 views
1

위젯을 삭제하여 Gtk.FlowBox에서 위젯을 제거하려고하지만 회색 상자가 남아 있습니다. 위젯이 제거 된 후 인접한 위젯이 제자리에 놓 이도록 회색 상자를 제거하는 방법에 대한 아이디어. 1- 두 이미지 (pixbuf 행) 및 라벨 2- 오버레이 이미지가 FlowBoxGtk.FlowBox에서 위젯 제거

첨가되는 EventBox를 -3- EventBox를 첨가하는 OverlayImage 첨가되어

다음은 위젯 포장 어떻게

나는 다음과 같은 방법을 시도 : 1 파괴 EventBox를 을 2 가져 오기 및 오버레이 이미지의 모든 어린이를 파괴하고 다음 두 경우 오버레이 이미지와 EventBox를

을 파괴, 위젯이 제거되지만 빈 지역 숙박 그 자리에 클릭하면 회색이지만 아무것도하지 않습니다 - 그림을보십시오.

빈 공간을 제거하려면 어떻게해야합니까? 다음 위젯이 자동으로 위젯이 제거 된 장소로 떨어지며 다음 위젯이 그 자리에 등등 떨어지게합니다.

코드 여기 가능하고 "removeSelectedBooksFromLibrary"는 FlowBox

이 중 사용자에 의해 선택된 EventBox를 제거 FlowBox에서 https://github.com/babluboy/bookworm/blob/master/src/bookworm.vala#L589

이것 위젯을 추가하는 코드하는 방법 사전

,369에 FlowBox에서 https://github.com/babluboy/bookworm/blob/master/src/bookworm.vala#L512

enter image description here 감사 위젯을 제거하는 코드는

다음은 위젯과 그 부모를 제거하는 솔루션이 추가 된 작업 예제입니다.

public class FlowBoxIssue : Gtk.Window { 

    public static int main (string[] args) { 
     Gtk.init (ref args); 
     FlowBoxIssue window = new FlowBoxIssue(); 
     window.show_all(); 
     Gtk.main(); 
     return 0; 
    } 

    public FlowBoxIssue() { 
     this.title = "FlowBox Issue"; 
     this.window_position = Gtk.WindowPosition.CENTER; 
     this.destroy.connect (Gtk.main_quit); 
     this.set_default_size (800, 600); 

     Gtk.FlowBox library_flowbox = new Gtk.FlowBox(); 
     Gtk.Box library_mainbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 20); 

     Gtk.ScrolledWindow library_scroll = new Gtk.ScrolledWindow (null, null); 
      library_scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); 
      library_scroll.add (library_flowbox); 

     Gtk.Overlay aOverlayImage1 = new Gtk.Overlay(); 
     Gtk.EventBox aEventBox1 = new Gtk.EventBox(); 
     Gtk.EventBox aEventBox2 = new Gtk.EventBox(); 
     Gtk.EventBox aEventBox3 = new Gtk.EventBox(); 
     try{ 
     Gdk.Pixbuf aBookCover1 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false); 
     Gtk.Image aCoverImage1 = new Gtk.Image.from_pixbuf(aBookCover1); 

     aOverlayImage1.add(aCoverImage1); 
     Gtk.Label overlayTextLabel1 = new Gtk.Label("Label 1"); 
     aOverlayImage1.add_overlay(overlayTextLabel1); 
     aEventBox1.add(aOverlayImage1); 
     library_flowbox.add (aEventBox1); 
     }catch(Error e){ 

     } 

     Gtk.Overlay aOverlayImage2 = new Gtk.Overlay(); 
     try{ 
     Gdk.Pixbuf aBookCover2 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false); 
     Gtk.Image aCoverImage2 = new Gtk.Image.from_pixbuf(aBookCover2); 

     aOverlayImage2.add(aCoverImage2); 
     Gtk.Label overlayTextLabel2 = new Gtk.Label("Label 2"); 
     aOverlayImage2.add_overlay(overlayTextLabel2); 
     aEventBox2.add(aOverlayImage2); 
     library_flowbox.add (aEventBox2); 
     }catch(Error e){ 

     } 

     Gtk.Overlay aOverlayImage3 = new Gtk.Overlay(); 
     try{ 
     Gdk.Pixbuf aBookCover3 = new Gdk.Pixbuf.from_file_at_scale("cover.png", 200, 250, false); 
     Gtk.Image aCoverImage3 = new Gtk.Image.from_pixbuf(aBookCover3); 

     aOverlayImage3.add(aCoverImage3); 
     Gtk.Label overlayTextLabel3 = new Gtk.Label("Label 3"); 
     aOverlayImage3.add_overlay(overlayTextLabel3); 
     aEventBox3.add(aOverlayImage3); 
     library_flowbox.add (aEventBox3); 
     }catch(Error e){ 

     } 

     Gtk.Button delete_button = new Gtk.Button.with_label("Delete Pix"); 
     delete_button.clicked.connect (() => { 
      //This is the line which resolved the issue - get the parent of the widget and destroy it and then destroy the widget 
      aEventBox2.get_parent().destroy(); 
       aEventBox2.destroy(); 
      }); 

     library_mainbox.pack_start(library_scroll, true, true, 0); 
     library_mainbox.pack_end(delete_button, true, false, 0); 
     this.add(library_mainbox); 
    } 

} 
+0

코드를 링크하는 것을 잊었습니다 (질문 [MCVE] (http://stackoverflow.com/help/mcve)). – andlabs

+0

코드 언급을 잊어 버린 것에 사과드립니다.나는 MCVE를 만들고 질문을 업데이트하려고 노력할 것입니다. –

답변

4

당신이 GtkFlowBox에 자식 위젯을 추가 할 때마다, 흐름 상자 위젯은 이벤트 처리 및 스타일링 목적 사이에 암시 적 자식 위젯을 추가합니다 - 문서로 GtkFlowBox 상태에 대해 :

GtkFlowBox에는 GtkFlowBoxChild 자식 만 있어야하지만 gtk_container_add()를 통해 모든 종류의 위젯을 추가 할 수 있으며 GtkFlowBoxChild 위젯이 상자와 위젯 사이에 자동으로 삽입됩니다.

library_grid.add(aEventBox); 

이 정말 동일합니다 :

이 라인을 의미

var flowbox_child = new Gtk.FlowBoxChild(); 
flowbox_child.add(aEventBox); 
library_grid.add(flowbox_child); 

당신이 GtkFlowBox에서 위젯을 제거 할 당신은 아이에 대한 참조를 유지하는 경우 추가했다면 부모를 검색하여 제거해야합니다. GtkFlowBox :

aEventBox.get_parent().destroy(); 
// or 
library_grid.remove(aEventBox.get_parent()); 
+0

귀하의 빠르고 매우 설명적인 답변에 많은 감사드립니다. 이 솔루션은 주요 코드와 MVCE에서 잘 작성되었습니다. 질문에 MVCE를 추가하면 같은 문제가있는 사람을 도울 수 있습니다. 부끄러워 내가 제대로 설명서를 읽지 못했습니다. 다시 한 번 감사드립니다! –