我试图在 wxWidgets/DialogBlocks 项目中节省一些水平空间。我认为我可以节省的一个地方是
wxColorPickerCtrl
的宽度,它似乎是 95 像素宽。
这似乎不必要地宽。然而,当我将其宽度设置为更好的值(例如 25px)时,我得到的东西非常难看。
有没有一种(支持的)方法可以让控件很好地缩小范围? 看起来好像这是可能的,因为我在 DialogBlocks 中创建它,当我在 GUI 构建器中插入控件时,应用程序向我展示了一些非常好的东西。然而,当我构建时它永远不会以这种方式呈现。
我知道 GUI 构建器向我显示一个控件,而不是静态图像(au3info 说它是一个按钮,与我检查由编译、运行的应用程序创建的窗口时它所说的相同),所以看起来这应该是有可能。我只是不知道怎么办。
我尝试了一些明智的(恕我直言)风格改变,但无济于事。选择器控件只是不会调整/剪辑渲染按钮上的图像。
有没有办法让控件变得非常小,比如正方形?我找不到任何这样的例子(在DialogBlocks GUI构建器之外)
我调试了我的简单项目,然后将 wxColourPickerCtrl 构造函数执行到
generic\clrpickerg.cpp
wxGenericColourButton::Create()
m_bitmap = wxBitmap( 60, 13 );
如果我将硬编码宽度更改为 13,则按钮看起来就像我想要的那样。 有没有办法改变这个不能完全访问的成员对象的底层位图?
根据答案的建议,我必须对 both
wxGenericColourButton
(更改位图)和 wxColourPickerCtrl
(使用新的按钮类)进行子类化。这将对 wxWidgets 内部的变化敏感,但我找不到更好的选择。
class _wxGenericColourButton : public wxGenericColourButton {
public:
_wxGenericColourButton() {}
_wxGenericColourButton( wxWindow *parent,
wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRBTN_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerWidgetNameStr )
{
Create(parent,id,col,pos,size,style,validator,name);
}
bool Create( wxWindow *parent,
wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRBTN_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerWidgetNameStr )
{
// Generally taken from wxGenericColourButton::Create() [clrpickerg.cpp:44]
// Make the bitmap smaller by default. Enlarging the button should work fine.
m_bitmap = wxBitmap(13, 13);
// create this button
if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
size, style | wxBU_AUTODRAW, validator, name ))
{
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
return false;
}
// and handle user clicks on it
Connect(GetId(), wxEVT_BUTTON,
wxCommandEventHandler(wxGenericColourButton::OnButtonClick),
NULL, this);
m_colour = col;
UpdateColour();
InitColourData();
return true;
}
};
class _wxColourPickerCtrl : public wxColourPickerCtrl {
public:
_wxColourPickerCtrl() {}
_wxColourPickerCtrl( wxWindow *parent, wxWindowID id,
const wxColour& col = *wxBLACK, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxCLRP_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerCtrlNameStr)
{
Create(parent, id, col, pos, size, style, validator, name);
}
bool Create( wxWindow *parent, wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRP_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerCtrlNameStr)
{
// This code is generally taken from: wxColourPickerCtrl::Create() [clrpickercmn.cpp:51]
if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size,
style, validator, name))
return false;
// Use our "enhanced" _wxGenericColourButton instead of the one with hardcoded,
// undesirable behavior.
m_picker = new _wxGenericColourButton(this, wxID_ANY, col,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle(style));
// Copied from clrpickercmn.cpp
wxPickerBase::PostCreation();
m_picker->Connect(wxEVT_COLOURPICKER_CHANGED,
wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
NULL, this);
return true;
}
};
不幸的是,没有干净的方法来解决这个错误。您可以从
wxGenericColourButton
派生并更改其 m_bitmap
,然后调用 UpdateColour()
,但这将使用未记录的 API,并且可能会发生变化,而且通常很难看。
这确实应该在
wxGenericColourButton
本身中修复,位图应该根据提供的大小计算(并且在大小变化时也会更新!)并且这应该不难做到。如果您决定尝试这样做,请随时将您的补丁提交到 wxWidgets。