xiezhongyuan / switchbutton Goto Github PK
View Code? Open in Web Editor NEWQT 实现的带有动画效果的 switch button 开关按钮。具体内容与效果可以查看博客 https://blog.csdn.net/xiezhongyuan07/article/details/93217781
QT 实现的带有动画效果的 switch button 开关按钮。具体内容与效果可以查看博客 https://blog.csdn.net/xiezhongyuan07/article/details/93217781
注意到在重写的鼠标事件中发送了emit statusChanged(m_checked);
但是在connect之后,槽函数并没有响应。
复现方法:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
....
SwitchButton *button = new SwitchButton(ui->listWidget);
button->setChecked(true);
}
一种解决方法:
1)修改setChecked()方法
if (m_checked != checked) {
m_checked = checked;
if (m_checked) {
m_endX = width() - height();
} else {
m_endX = 0;
}
m_startX = m_endX;
update();
}
2)SwitchButton类重载QWidget父类的resizeEvent()事件
void SwitchButton::resizeEvent(QResizeEvent *event)
{
if (m_checked) {
m_endX = width() - height();
} else {
m_endX = 0;
}
m_startX = m_endX;
update();
QWidget::resizeEvent(event);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.