【问题标题】:Is there a way to connect a QSlider and a QLineEdit object to each other?有没有办法将 QSlider 和 QLineEdit 对象相互连接?
【发布时间】:2021-06-17 23:38:48
【问题描述】:

我正在尝试将 Slider 和 LineEdit 小部件连接在一起,以便在更改其中一个时,另一个将匹配此值。

我很挣扎,因为 lineEdit 需要字符串,而 Slider 需要整数。我已经在 lineEdit 上使用了 setValidator,所以只能输入整数。

我尝试使用旧的信号和插槽语法,但没有通过快速 Google 搜索使用几种不同的方法。

connect(textbox, SIGNAL(textEdited(QString)),slider,
        SLOT((QString)));

我应该使用与 LineEdit 完全不同的小部件吗?

【问题讨论】:

    标签: c++ qt slider signals-slots qlineedit


    【解决方案1】:

    使用QSpinBox()lineEdit()方法:

    connect(textbox, &QLineEdit::textEdited, slider->lineEdit(), &QLineEdit::setText);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      相关资源
      最近更新 更多