2018-07-11 19:18:50 +01:00
|
|
|
#include "noscrollcombobox.h"
|
|
|
|
|
2019-08-07 02:50:03 +01:00
|
|
|
#include <QCompleter>
|
|
|
|
|
2018-07-11 19:18:50 +01:00
|
|
|
NoScrollComboBox::NoScrollComboBox(QWidget *parent)
|
|
|
|
: QComboBox(parent)
|
|
|
|
{
|
|
|
|
// Don't let scrolling hijack focus.
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2019-08-07 02:50:03 +01:00
|
|
|
|
|
|
|
// Make speed a priority when loading comboboxes.
|
2019-08-19 03:33:36 +01:00
|
|
|
setMinimumContentsLength(24);// an arbitrary limit
|
2021-02-06 00:43:49 +00:00
|
|
|
setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
2019-08-07 02:50:03 +01:00
|
|
|
|
|
|
|
// Allow items to be searched by any part of the word, displaying all matches.
|
|
|
|
setEditable(true);// can set to false manually when using
|
|
|
|
this->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
|
|
|
this->completer()->setFilterMode(Qt::MatchContains);
|
2021-09-07 22:35:55 +01:00
|
|
|
|
2021-09-08 22:25:21 +01:00
|
|
|
QRegularExpression re("[^\\s]*");
|
2021-09-07 22:35:55 +01:00
|
|
|
QValidator *validator = new QRegularExpressionValidator(re);
|
|
|
|
this->setValidator(validator);
|
2018-07-11 19:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoScrollComboBox::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
// Only allow scrolling to modify contents when it explicitly has focus.
|
|
|
|
if (hasFocus())
|
|
|
|
QComboBox::wheelEvent(event);
|
|
|
|
}
|