diff --git a/include/GuiApplication.h b/include/GuiApplication.h index 8b4284c026b..825c258372e 100644 --- a/include/GuiApplication.h +++ b/include/GuiApplication.h @@ -28,6 +28,7 @@ #include #include "lmms_export.h" +#include "lmmsconfig.h" class QLabel; @@ -48,6 +49,9 @@ class LMMS_EXPORT GuiApplication : public QObject ~GuiApplication(); static GuiApplication* instance(); +#ifdef LMMS_BUILD_WIN32 + static QFont getWin32SystemFont(); +#endif MainWindow* mainWindow() { return m_mainWindow; } FxMixerView* fxMixerView() { return m_fxMixerView; } diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index a7d78bf5463..a6f01c54187 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -55,8 +55,6 @@ #include "StringPairDrag.h" #include "TextFloat.h" - - enum TreeWidgetItemTypes { TypeFileItem = QTreeWidgetItem::UserType, @@ -335,6 +333,13 @@ FileBrowserTreeWidget::FileBrowserTreeWidget(QWidget * parent ) : connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), SLOT( updateDirectory( QTreeWidgetItem * ) ) ); +#if QT_VERSION < QT_VERSION_CHECK(5, 12, 2) && defined LMMS_BUILD_WIN32 + // Set the font for the QTreeWidget to the Windows System font to make sure that + // truncated (elided) items use the same font as non-truncated items. + // This is a workaround for this qt bug, fixed in 5.12.2: https://bugreports.qt.io/browse/QTBUG-29232 + // TODO: remove this when all builds use a recent enough version of qt. + setFont( GuiApplication::getWin32SystemFont() ); +#endif } diff --git a/src/gui/GuiApplication.cpp b/src/gui/GuiApplication.cpp index fb2e3eae376..dbd95cdfc25 100644 --- a/src/gui/GuiApplication.cpp +++ b/src/gui/GuiApplication.cpp @@ -45,6 +45,10 @@ #include #include +#ifdef LMMS_BUILD_WIN32 +#include +#endif + GuiApplication* GuiApplication::s_instance = nullptr; GuiApplication* GuiApplication::instance() @@ -211,3 +215,24 @@ void GuiApplication::childDestroyed(QObject *obj) m_controllerRackView = nullptr; } } + +#ifdef LMMS_BUILD_WIN32 +/*! + * @brief Returns the Windows System font. + */ +QFont GuiApplication::getWin32SystemFont() +{ + NONCLIENTMETRICS metrics = { sizeof( NONCLIENTMETRICS ) }; + SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( NONCLIENTMETRICS ), &metrics, 0 ); + int pointSize = metrics.lfMessageFont.lfHeight; + if ( pointSize < 0 ) + { + // height is in pixels, convert to points + HDC hDC = GetDC( NULL ); + pointSize = MulDiv( abs( pointSize ), 72, GetDeviceCaps( hDC, LOGPIXELSY ) ); + ReleaseDC( NULL, hDC ); + } + + return QFont( QString::fromUtf8( metrics.lfMessageFont.lfFaceName ), pointSize ); +} +#endif