QSpinBox
makes its contents selected (highlighted) upon using up/down buttons. Is there any way to disable this?
Is there any way to clear selection, other than use my own subclass of QSpinBox
to access the underlying QLineEdit
?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There's no way to directly disable it, but you can do a bit of a hack:
void Window::onSpinBoxValueChanged() // slot
{
spinBox->findChild<QLineEdit*>()->deselect();
}
I recommend connecting to this using a queued connection, like this:
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(onSpinBoxValueChanged()), Qt::QueuedConnection);
This will ensure that the slot is called after the line edit is highlighted.