如何使 wxColorPickerCtrl 变窄?
How can I make a wxColorPickerCtrl narrower?
wxColourPickerCtrl (WXMSW): 能再窄一点不难看吗?
我正在尝试在 wxWidgets/DialogBlocks 项目中保存一些水平 space。我认为我可以节省的一个地方是 wxColorPickerCtrl
的宽度,它似乎是 95 像素宽。
这似乎不必要地宽。但是,当我将其宽度设置为更好的值(例如 25px)时,我得到的结果非常丑陋。
是否有(支持的)方法可以很好地缩小控件的范围?
这似乎是可能的,因为我在 DialogBlocks 中创建它,当我在 GUI 构建器中插入控件时,应用程序向我展示了一些非常好的东西。但是,当我构建时它永远不会那样呈现。
我知道 GUI 构建器向我显示的是一个控件而不是静态图像(au3info 说它是一个按钮,与我检查由已编译的 window 创建的 [=64] 时所说的相同=] 应用程序),所以这似乎应该是可能的。我只是不知道如何。
我尝试了一些合理的(恕我直言)样式更改,但无济于事。选择器控件不会 resize/clip 渲染按钮上的图像。
有没有办法让控件变得非常小,比如正方形?我找不到任何这样的例子(在 DialogBlocks GUI 构建器之外)
附录
我调试了我的简单项目,然后将 wxColourPickerCtrl 构造函数执行到 generic\clrpickerg.cpp
wxGenericColourButton::Create()
m_bitmap = wxBitmap( 60, 13 );
如果我将硬编码宽度更改为 13,按钮看起来就像我想要的那样。
有没有办法改变这个不能完全访问的成员对象的底层位图?
黑客解决方案
根据答案的建议,我不得不子class both wxGenericColourButton
(改变位图)和wxColourPickerCtrl
(使用新按钮 class)。这对 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。
wxColourPickerCtrl (WXMSW): 能再窄一点不难看吗?
我正在尝试在 wxWidgets/DialogBlocks 项目中保存一些水平 space。我认为我可以节省的一个地方是 wxColorPickerCtrl
的宽度,它似乎是 95 像素宽。
这似乎不必要地宽。但是,当我将其宽度设置为更好的值(例如 25px)时,我得到的结果非常丑陋。
是否有(支持的)方法可以很好地缩小控件的范围? 这似乎是可能的,因为我在 DialogBlocks 中创建它,当我在 GUI 构建器中插入控件时,应用程序向我展示了一些非常好的东西。但是,当我构建时它永远不会那样呈现。
我知道 GUI 构建器向我显示的是一个控件而不是静态图像(au3info 说它是一个按钮,与我检查由已编译的 window 创建的 [=64] 时所说的相同=] 应用程序),所以这似乎应该是可能的。我只是不知道如何。
我尝试了一些合理的(恕我直言)样式更改,但无济于事。选择器控件不会 resize/clip 渲染按钮上的图像。
有没有办法让控件变得非常小,比如正方形?我找不到任何这样的例子(在 DialogBlocks GUI 构建器之外)
附录
我调试了我的简单项目,然后将 wxColourPickerCtrl 构造函数执行到 generic\clrpickerg.cpp
wxGenericColourButton::Create()
m_bitmap = wxBitmap( 60, 13 );
如果我将硬编码宽度更改为 13,按钮看起来就像我想要的那样。 有没有办法改变这个不能完全访问的成员对象的底层位图?
黑客解决方案
根据答案的建议,我不得不子class both wxGenericColourButton
(改变位图)和wxColourPickerCtrl
(使用新按钮 class)。这对 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。