{"id":3920,"date":"2021-12-21T10:55:41","date_gmt":"2021-12-21T10:55:41","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3920"},"modified":"2021-12-21T10:55:43","modified_gmt":"2021-12-21T10:55:43","slug":"5b-5-wxwidgets-gridbagsizer","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/21\/5b-5-wxwidgets-gridbagsizer\/","title":{"rendered":"5b-5. wxWidgets  &#8211; GridBagSizer"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>wxGridBagSizer adds more complexity to the wxFlexGridSizer by allowing controls to span multiple rows or columns. We can even specify which row or column to place a control in. This manipulation of placements can be done at runtime as well.<\/p>\n\n\n\n<p>The constructor of wxGridBagSizer does not specify the number of rows or columns. It only specifies the horizontal and vertical gap between the cells.<\/p>\n\n\n\n<p>The sample code below replicates the same window as in wxFlexGridSizer but using wxGridBagSizer<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gridbagsizer.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n#include &lt;wx\/gbsizer.h&gt;\n\nclass GridBagSizer: public wxFrame {\n\tpublic:\n\t\tGridBagSizer(const wxString &amp;title);\t\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">gridbagsizer.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;gridbagsizer.h&quot;\n\nGridBagSizer::GridBagSizer(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,250)) {\n\n\twxPanel *basePanel = new wxPanel(this,-1);\n\twxGridBagSizer *gbs = new wxGridBagSizer(3,4);\n\tgbs-&gt;SetEmptyCellSize(wxSize(20,10));\n\tbasePanel-&gt;SetSizer(gbs);\n\n\twxStaticText *lblA1=  new wxStaticText(basePanel, -1, wxT(&quot;Answer 1&quot;));\n\twxStaticText *lblA2=  new wxStaticText(basePanel, -1, wxT(&quot;Answer 2&quot;));\n\twxStaticText *lblA3=  new wxStaticText(basePanel, -1, wxT(&quot;Answer 3&quot;));\n\twxStaticText *lblA4=  new wxStaticText(basePanel, -1, wxT(&quot;Answer 4&quot;));\n\n\n\twxTextCtrl *txtA1=  new wxTextCtrl(basePanel, -1, wxT(&quot;&quot;));\n\twxTextCtrl *txtA2=  new wxTextCtrl(basePanel, -1, wxT(&quot;&quot;));\n\twxTextCtrl *txtA3=  new wxTextCtrl(basePanel, -1, wxT(&quot;&quot;));\n\twxTextCtrl *txtA4=  new wxTextCtrl(basePanel, -1, wxT(&quot;&quot;), wxPoint(-1,-1), wxSize(-1,-1), wxTE_MULTILINE);\n\n\tgbs-&gt;Add(lblA1, wxGBPosition(0,0), wxGBSpan(1,1), wxEXPAND);\n\tgbs-&gt;Add(lblA2, wxGBPosition(1,0), wxGBSpan(1,1), wxEXPAND);\n\tgbs-&gt;Add(lblA3, wxGBPosition(2,0), wxGBSpan(1,1), wxEXPAND);\n\tgbs-&gt;Add(lblA4, wxGBPosition(3,0), wxGBSpan(1,1), wxEXPAND);\n\n\tgbs-&gt;Add(txtA1, wxGBPosition(0,1), wxGBSpan(1,4), wxEXPAND);\n\tgbs-&gt;Add(txtA2, wxGBPosition(1,1), wxGBSpan(1,4), wxEXPAND);\n\tgbs-&gt;Add(txtA3, wxGBPosition(2,1), wxGBSpan(1,4), wxEXPAND);\n\tgbs-&gt;Add(txtA4, wxGBPosition(3,1), wxGBSpan(4,4), wxEXPAND);\n\n\tgbs-&gt;AddGrowableRow(3);\n\tgbs-&gt;AddGrowableCol(1);\n\tCenter();\n}\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"329\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-21-16-24-20.png\" alt=\"\" class=\"wp-image-3923\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-21-16-24-20.png 606w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-21-16-24-20-300x163.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW wxGridBagSizer adds more complexity to the wxFlexGridSizer by allowing controls to span multiple rows or columns. We can even specify which row or column <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/21\/5b-5-wxwidgets-gridbagsizer\/\" title=\"5b-5. wxWidgets  &#8211; GridBagSizer\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-3920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3920"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3920\/revisions"}],"predecessor-version":[{"id":3924,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3920\/revisions\/3924"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}