Add MonitorSelectionWidget

Refreshes list of monitors when widget becomes visible to support widget
caching
This commit is contained in:
WarmUpTill
2025-05-21 15:50:34 +02:00
committed by WarmUpTill
parent c281c6db83
commit 5ce4171773
6 changed files with 37 additions and 9 deletions

View File

@@ -47,4 +47,23 @@ QStringList GetMonitorNames()
return monitorNames;
}
MonitorSelectionWidget::MonitorSelectionWidget(QWidget *parent)
: FilterComboBox(parent)
{
setEditable(true);
SetAllowUnmatchedSelection(true);
setMaxVisibleItems(20);
addItems(GetMonitorNames());
}
void MonitorSelectionWidget::showEvent(QShowEvent *event)
{
FilterComboBox::showEvent(event);
const QSignalBlocker b(this);
const auto text = currentText();
clear();
addItems(GetMonitorNames());
setCurrentText(text);
}
} // namespace advss

View File

@@ -1,8 +1,18 @@
#pragma once
#include <QStringList>
#include "filter-combo-box.hpp"
namespace advss {
QStringList GetMonitorNames();
class MonitorSelectionWidget : public FilterComboBox {
Q_OBJECT
public:
MonitorSelectionWidget(QWidget *parent);
protected:
void showEvent(QShowEvent *event) override;
};
} // namespace advss