在 Qt 中动态创建 QSlider 以及关联的 QLCDNumber
我想知道解决以下场景的最佳方法是什么?
我正在动态创建 QSlider,我希望将其链接到关联的 QLCDNumber 进行显示。问题是我希望有十分之一可用,所以我希望在 QSLider 和 QLCDNumber 之间进行转换以除以 10。此时,我真正保留的只是 QSlider,即我刚刚创建并忘记的 QLCDNumber。有没有一种简单的方法可以进行转换和连接,而不必保留太多信息?
提前致谢。
I was wondering what's the best way to go about the following scenario?
I am dynamically creating QSliders that I wish to link to an associated QLCDNumber for display. The thing is I would like to have tenths available, so I would like to have a conversion between the QSLider and the QLCDNumber to divide by 10. At this point all I keep really is the QSlider, the QLCDNumbers I just create and forgot about. Is there an easy way of doing the conversion and connection without having to keep too much information?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试以下方法:
之后您可以完全“忘记”您的液晶显示屏编号,即您不需要保留指针或参考。
编辑:多个滑块的解决方案:
现在创建
MySlider
实例而不是QSlider
实例并连接您的QLCDNumbers
:这样您还可以实现不同的转换等因素,只需修改
MySlider
实现即可。我希望这有帮助。
I'd try something along the following lines:
Afterwards you can completely "forget" about your LCD number, i.e. you don't need to keep a pointer or reference.
EDIT: A solution for several sliders:
Now create
MySlider
instances instead ofQSlider
ones and connect yourQLCDNumbers
:This way you can also implement different conversion factors and the like, just modify the
MySlider
implementation.I hope that helps.
这基本上就是我最终使用的;它似乎有效(尽管它违反了整个面向对象的哲学)。
This is basically what I ended up using; it seems to work (though it violates the whole object oriented philosophy).