是否可以这样做,以便如果我在程序中为旋转框设置值,它不会突出显示更改的字段或添加光标。我已经包含了下面一些插槽的代码,它控制一个最小值和最大值字段,并在 min>max 等情况下更改另一个。第二个插槽表现出所需的行为,但如果您在键入值后单击旋转控件会崩溃(没有返回)。我所有的旋转框都关闭了键盘跟踪。
void show_graph::on_vmin_dspinBox_valueChanged(double arg1)
{
active = false; /*flag to stop cyclic interactions*/
if (arg1>=ui->vmax_dSpinBox->value())
{
ui->vmax_dSpinBox->setValue(arg1);
ui->vmax_dSpinBox->stepUp();
}
active = true;
}
第二种方法很丑陋,并试图操纵焦点。
void show_graph::on_fmin_dspinBox_valueChanged(double arg1)
{
active = false;
QWidget *active_item;
if (QApplication::focusWidget()!=0)
active_item = QApplication::focusWidget(); /*save focus*/
if (arg1>=ui->fmax_dspinBox->value())
{
ui->fmax_dspinBox->setValue(arg1);
ui->fmax_dspinBox->stepUp();
}
ui->fmax_dspinBox->cursor(); /*move focus to changed widget*/
ui->fmax_dspinBox->setFocus();
ui->fmax_dspinBox->unsetCursor(); /*then remove to lose highlight and cursor*/
ui->fmax_dspinBox->clearFocus();
active_item->setFocus(); /*know I'm missing check of if active item set but this doesn't appear to be the issue*/
active_item->cursor(); /*reset focus/cursor to where user wanted*/
active = true;
}
上面的代码在 editorFinished 插槽中使用时也会崩溃。试图获取问题的屏幕截图,但按下打印屏幕会删除不需要的突出显示/光标。我是 QT 的新手,因此如果这是一种愚蠢的做法,请这样说,或者如果答案在文档中,请指出我正确的方向。如果有任何不同,我正在 Linux 上进行开发和测试。