如何创建 Qt 组合框
您好,想用许多项目填充 QCombobox
,这些项目等于 QSpinBox
中设置的变量
当将 QSpinbox
值更改为 N 时,则组合框应显示相同数量的选项,编号从 0 到 N。
是否可以使用 QObject::connect 来实现
Hi would like to populate a QCombobox
with a number of items which equals a variable set in a QSpinBox
When varying the QSpinbox
value to N , then the combobox should show the same number of options numbered from 0 to N.
Is it possible to do it with a QObject::connect
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用信号
QSpinBox::valueChanged (int i)
。实现您自己的从
QComboBox
派生的类,并创建一个与信号具有相同签名的槽。类似于:
然后您可以将信号连接到插槽。
在槽中,您清除组合框 (
QComboBox::clear ()
),然后使用循环,在其中创建与槽中从信号接收的整数指定的项目数相同的项目。You can use the signal
QSpinBox::valueChanged ( int i )
.Implement your own class which derives from
QComboBox
and create a slot which has the same signature as the signal.Something like:
Then you can connect the signal to the slot.
In the slot you clear the combobox (
QComboBox::clear ()
) and then use a loop in which you create as many items as specified by the integer you received in your slot from your signal.