Spacing/empty border for wxWidgets

筅森魡賤 提交于 2019-12-13 02:55:44

问题


Is there anything you can use to add space around the edges of a window or between components with wxWidgets/wxPython? I want something to prevent components from being squished up against the window border or each other, similar to what can be done with Java Swing's EmptyBorder or Insets. (I know you can set horizontal/vertical gaps with some sizers, but I'd like something more flexible.)


回答1:


See the border parameter in the Sizer's Add method. You can use the flag parameter to tell it where to put the border, such as wx.ALL, wx.RIGHT, wx.LEFT, wx.TOP, etc.

This can be used to put space around widgets and between widgets. Sometimes you might want to use the sizer's AddSpacer to add space. Or you can just do something like this:

mySizer.Add((20, 100))

What that does is put 100 pixels between two widgets on the y axis. You'll probably have to play with it a bit to get it the way you want.

See also http://wiki.wxpython.org/GridSizerTutorial or http://zetcode.com/wxpython/layout/




回答2:


The sizers provided by wxWidgets are very flexible. Are you sure you have explored all that they are capable of? It is hard to imagine what you might need that they cannot handle. Please describe exactly what you need and post the code which you have tried so far.

Here is an example:

sizer->Add(new wxButton(this, -1, "Button with 20 pixel border all round"),
      0,  wxALL, 20);

Here is a demo of more sizer options. http://neume.sourceforge.net/sizerdemo/

If you really cannot use sizers to achieve what you need, then you can explicitly position each widget wherever you want by passing in a location to the widget constructor.

wxPoint button_position( 50,50 );   // position button 50 pixel down and to right of top left
new wxButton(this, -1, "Button", button_position )


来源:https://stackoverflow.com/questions/9306808/spacing-empty-border-for-wxwidgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!