- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
1 Câu trả lời
我实现了 SplitButton,它看起来像:
SplitButton.h
#ifndef __SPLIT_BUTTON_H__
#define __SPLIT_BUTTON_H__
#include
#include
class SplitButton : public wxPanel
{
công cộng:
SplitButton(wxWindow *parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize);
~SplitButton();
wxMenu* GetSplitButtonMenu();
protected:
void OnKillFocus(wxFocusEvent& event);
void OnMouseLeave(wxMouseEvent& event);
void OnMouseEnter(wxMouseEvent& event);
void OnLeftButtonUp(wxMouseEvent& event);
void OnLeftButtonDown(wxMouseEvent& event);
void OnPaint(wxPaintEvent& WXUNUSED(event));
bool Enable(bool enable = true) override;
riêng tư:
int m_stateButton = 0;
int m_stateMenu = 0;
bool m_bIsEnable = true;
wxColor m_colorNormal;
wxColor m_colorDisabled;
const int m_arrowButtonWidth = 20;
bool m_bLButtonDown = false;
wxString m_label;
wxMenu* m_pMenu = nullptr;
};
#endif /*__SPLIT_BUTTON_H__*/
SplitButton.cpp
#include "SplitButton.h"
#include
SplitButton::SplitButton(wxWindow *parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size)
: wxPanel(parent, id, pos, size, wxBORDER_NONE | wxTAB_TRAVERSAL, "DropDownButton"),
m_label(label)
{
m_colorNormal = GetForegroundColour();
m_colorDisabled = GetForegroundColour().MakeDisabled();
if (size == wxDefaultSize)
{
wxSize defaultSize = wxButton::GetDefaultSize();
wxSize textSize = GetTextExtent(m_label);
textSize.SetWidth(textSize.GetWidth() + m_arrowButtonWidth + 20);
SetMinSize(wxSize(textSize.GetWidth(), defaultSize.GetHeight()));
}
Bind(wxEVT_PAINT, &SplitButton::OnPaint, this);
Bind(wxEVT_LEFT_UP, &SplitButton::OnLeftButtonUp, this);
Bind(wxEVT_LEFT_DOWN, &SplitButton::OnLeftButtonDown, this);
Bind(wxEVT_KILL_FOCUS, &SplitButton::OnKillFocus, this);
Bind(wxEVT_LEAVE_WINDOW, &SplitButton::OnMouseLeave, this);
Bind(wxEVT_ENTER_WINDOW, &SplitButton::OnMouseEnter, this);
m_pMenu = new wxMenu();
}
SplitButton::~SplitButton()
{
delete m_pMenu;
m_pMenu = nullptr;
}
wxMenu* SplitButton::GetSplitButtonMenu()
{
return m_pMenu;
}
void SplitButton::OnKillFocus(wxFocusEvent& event)
{
m_stateButton = wxCONTROL_CURRENT;
m_stateMenu = wxCONTROL_CURRENT;
Refresh();
event.Skip();
}
void SplitButton::OnMouseLeave(wxMouseEvent& event)
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
event.Skip();
}
void SplitButton::OnMouseEnter(wxMouseEvent& event)
{
m_stateButton = wxCONTROL_CURRENT;
m_stateMenu = wxCONTROL_CURRENT;
Refresh();
event.Skip();
}
void SplitButton::OnLeftButtonUp(wxMouseEvent& event)
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
int x = -1;
int y = -1;
event.GetPosition(&x, &y);
if (x < (GetSize().GetWidth() - m_arrowButtonWidth))
{
wxEvtHandler* pEventHandler = GetEventHandler();
wxASSERT(pEventHandler);
pEventHandler->CallAfter([=]()
{
wxCommandEvent evt(wxEVT_BUTTON, this->GetId());
evt.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
});
}
m_bLButtonDown = false;
event.Skip();
}
void SplitButton::OnLeftButtonDown(wxMouseEvent& event)
{
m_bLButtonDown = true;
int x = -1;
int y = -1;
event.GetPosition(&x, &y);
if (x >= (GetSize().GetWidth() - m_arrowButtonWidth))
{
m_stateButton = 0;
m_stateMenu = wxCONTROL_PRESSED;
Refresh();
wxSize size = GetSize();
wxPoint position;
position.x = 0;
position.y = size.GetHeight();
PopupMenu(m_pMenu, position);
m_stateMenu = 0;
Refresh();
}
khác
{
m_stateButton = wxCONTROL_PRESSED;
m_stateMenu = wxCONTROL_PRESSED;
Refresh();
}
event.Skip();
}
void SplitButton::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
wxSize size = GetSize();
const int width = size.GetWidth() - m_arrowButtonWidth;
// Draw first part of button
wxRect r1;
r1.x = 0;
r1.y = 0;
r1.width = width + 2;
r1.height = size.GetHeight();
wxRendererNative::Get().DrawPushButton(this, dc, r1, m_stateButton);
SetForegroundColour(m_bIsEnable ? m_colorNormal : m_colorDisabled);
r1.y += (size.GetHeight() - GetCharHeight()) / 2;
dc.DrawLabel(m_label, r1, wxALIGN_CENTER_HORIZONTAL);
// Draw second part of button
wxRect r2;
r2.x = width - 2;
r2.y = 0;
r2.width = m_arrowButtonWidth;
r2.height = size.GetHeight();
wxRendererNative::Get().DrawPushButton(this, dc, r2, m_stateMenu);
wxRendererNative::Get().DrawDropArrow(this, dc, r2, m_stateMenu);
}
bool SplitButton::Enable(bool enable)
{
m_bIsEnable = enable;
wxPanel::Enable(m_bIsEnable);
if (m_bIsEnable)
{
m_stateButton = 0;
m_stateMenu = 0;
}
khác
{
m_stateButton = wxCONTROL_DISABLED;
m_stateMenu = wxCONTROL_DISABLED;
}
wxPaintEvent event;
ProcessEvent(event);
Refresh();
return enable;
}
关于wxwidgets - (推+下拉)按钮wxWidgets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37076881/
我刚刚在我的雪豹机器上下载了 wxWidget 源代码。源代码是多平台的,所以它也包含 wxWidget 的 windows 和 GTK 组件。我想编译 wxWidget 源代码,但还没有找到好的指南
我正在使用 C++/wxWidgets 开发一个小型应用程序,其中 GUI 的几个部分需要根据例如更新。收到 UDP 数据报。更具体地说,辅助线程尝试在网络中保留可用“客户端”的列表(可能会出现和消失
我在顶层窗口中有一个 wxPanel 的子类,上面有几层 wxSplitter。当显示窗口时,会发生一些调整大小和布局。当它完成时,我的面板背景在其某些背景上有随机垃圾(黑色或窗口的其他部分)。这似乎
作为 wxWidgets 的新手,我需要一些关于如何让 wxTimer 工作的示例代码。 The reference提供了 3 种使用方法,但不包含其中任何一种的示例代码。最理想的是,我想让方法 2
wxWidgets 库包括一个简单的 HTML 解析器和查看器,我试图用它来显示一些简单的 HTML。我想将某些链接(指向尚不存在的项目的链接)设置为不同的颜色,或者以其他方式表明需要创建它们,但我没
我想将同步事件从工作线程发送到 UI 主线程。我如何在 wxWidgets 中做到这一点? sample 的链接真的很有帮助 最佳答案 您应该使用 队列事件(wxEvent* 事件)用于线程间通信。
任何人都可以推荐 CLion 和 wxWdgets 的教程或入门指南吗?我四处寻找,但找不到任何东西。 最佳答案 好, 你应该在这里下载 WxWidgets http://www.wxwidgets.
希望有人能帮我解决这个问题。我正在使用 Visual Studio 2005 并创建一个静态链接到 wxWidgets 中的静态库。我有: 根据他们的指南静态编译wxWidgets 在我的“附加库目录
我目前正在设计将我现有的 .NET/C#/WinForms 项目迁移到一个平台中立的解决方案,我见过的最有吸引力的替代方案似乎是 wxWidgets,特别是考虑到我对 C++ 和 MFC 的熟悉,这似
几周以来,我一直被 wxWidgets 淹没。但是,我需要一些帮助: 动态链接 Unicode、Release、Non-monolithic 版本的 wxWidgets 3.0.0 时,如何链接以下库
我正在尝试一个新的设置。我使用的是 32 位 Windows 8 Pro 笔记本电脑。我已经下载了 MinGW-builds 的 GCC 4.8.1。我用它来编译 LLVM 和 CLang(3.4+
我正在寻找一个如何使用 WxWidgets 在 Windows 上创建 DLL 库的简单示例。 我需要在 DLL 上使用一些 wxWidgets API,它会从 Delphi 调用。 最佳答案 在您的
打包 Perl wxWidgets 应用程序以分发给未安装 Perl 或 wxWidgets 的 Windows 和 Mac 用户的最佳方法是什么? 有问题的用户不是很懂电脑,所以不能指望他们单独安装
我在处理一些用wxWidgets 2.8 编写的代码,现在需要转移到wxWidgets 2.9。 我这样定义: wxLocale m_locale; 和使用 m_locale.Init(iLocale
我在 linux 或 FreeBSD 上构建 wxWidgets 库时注意到 wxWidgets 需要其他 GUI 库,例如 GTK+、Motif 等,而 GTK+、Motif 或 FLTK 库似乎是
这是一个关于 wxBoxSizer 的问题。我正在实现一个自定义 wxWidget,如可折叠 Pane 。 问题是:我有一个 wxBoxSizer (Sizer1),我添加了另一个 wxBoxSize
我正在尝试编译 wxwidgets。我正在使用 mingw32 进行编译并遵循 zip 文件附带的 install.txt,但是当我编译它时,它给了我这些错误。 如果不存在 gcc_mswd mkdi
我想了解新的主要 wxWidgets 3.0 版本的学习资源。我看到网上有很多旧版本的资源,还有 2005 年的一本书。但我不确定它们是否合适。 Web 教程将是最好的,但欢迎任何内容。 如前所述,我
wxWidgets应用程序在主窗口的状态栏中显示普通菜单项的帮助字符串。不幸的是,对于使用wxWindow::PopupMenu命令调用的菜单,它似乎没有显示它们,我需要这样做。 我尝试将EVT_ME
如何获取模块路径? 我正在编写包含在 DLL 中的扩展,并希望在运行时获取我的库的路径。 更新 当然第一种方法很好用 static wxString GetModulePath() { sta
Tôi là một lập trình viên xuất sắc, rất giỏi!