Skip to content

Commit 686834c

Browse files
frontend: Set cursor width for OBSHotkeyEdit to 0
This hides the cursor from the OBSHotkeyEdit spin boxes even when they are in focus. Uses a shared style owned by OBSApp. # Conflicts: # frontend/utility/OBSProxyStyle.hpp
1 parent 4c91235 commit 686834c

5 files changed

Lines changed: 34 additions & 0 deletions

File tree

frontend/OBSApp.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <components/Multiview.hpp>
2121
#include <utility/OBSEventFilter.hpp>
22+
#include <utility/OBSProxyStyle.hpp>
2223
#if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
2324
#include <utility/models/branches.hpp>
2425
#endif
@@ -1223,6 +1224,14 @@ bool OBSApp::TranslateString(const char *lookupVal, const char **out) const
12231224
return text_lookup_getstr(App()->GetTextLookup(), lookupVal, out);
12241225
}
12251226

1227+
QStyle *OBSApp::GetInvisibleCursorStyle()
1228+
{
1229+
if (!invisibleCursorStyle) {
1230+
invisibleCursorStyle = std::make_unique<OBSInvisibleCursorProxyStyle>();
1231+
}
1232+
return invisibleCursorStyle.get();
1233+
}
1234+
12261235
// Global handler to receive all QEvent::Show events so we can apply
12271236
// display affinity on any newly created windows and dialogs without
12281237
// caring where they are coming from (e.g. plugins).

frontend/OBSApp.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class OBSApp : public QApplication {
9494
OBSTheme *currentTheme = nullptr;
9595
QHash<QString, OBSTheme> themes;
9696
QPointer<QFileSystemWatcher> themeWatcher;
97+
std::unique_ptr<QStyle> invisibleCursorStyle;
9798

9899
void FindThemes();
99100

@@ -137,6 +138,7 @@ private slots:
137138
OBSTheme *GetTheme(const QString &name);
138139
bool SetTheme(const QString &name);
139140
bool IsThemeDark() const { return currentTheme ? currentTheme->isDark : false; }
141+
QStyle *GetInvisibleCursorStyle();
140142

141143
void SetBranchData(const std::string &data);
142144
std::vector<UpdateBranch> GetBranches();

frontend/settings/OBSHotkeyEdit.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <obs.hpp>
2121

22+
#include <OBSApp.hpp>
23+
2224
#include <QLineEdit>
2325

2426
class OBSBasicSettings;
@@ -45,13 +47,15 @@ class OBSHotkeyEdit : public QLineEdit {
4547
{
4648
setAttribute(Qt::WA_InputMethodEnabled, false);
4749
setAttribute(Qt::WA_MacShowFocusRect, true);
50+
setStyle(App()->GetInvisibleCursorStyle());
4851
InitSignalHandler();
4952
ResetKey();
5053
}
5154
OBSHotkeyEdit(QWidget *parent = nullptr) : QLineEdit(parent), original({}), settings(nullptr)
5255
{
5356
setAttribute(Qt::WA_InputMethodEnabled, false);
5457
setAttribute(Qt::WA_MacShowFocusRect, true);
58+
setStyle(App()->GetInvisibleCursorStyle());
5559
InitSignalHandler();
5660
ResetKey();
5761
}

frontend/utility/OBSProxyStyle.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ int OBSProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const Q
1313

1414
return QProxyStyle::styleHint(hint, option, widget, returnData);
1515
}
16+
17+
int OBSInvisibleCursorProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
18+
const QWidget *widget) const
19+
{
20+
21+
if (metric == PM_TextCursorWidth)
22+
return 0;
23+
24+
return QProxyStyle::pixelMetric(metric, option, widget);
25+
}

frontend/utility/OBSProxyStyle.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ class OBSProxyStyle : public QProxyStyle {
1313
int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget,
1414
QStyleHintReturn *returnData) const override;
1515
};
16+
17+
class OBSInvisibleCursorProxyStyle : public OBSProxyStyle {
18+
Q_OBJECT
19+
20+
public:
21+
OBSInvisibleCursorProxyStyle() : OBSProxyStyle() {}
22+
23+
int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const override;
24+
};

0 commit comments

Comments
 (0)