Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SbQtHelper.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifndef _SB_QT_HELPER
25#define _SB_QT_HELPER
26
27#include <QCoreApplication>
28#include <QString>
29#include <QFile>
30#include <QWidget>
31
32#include <Inventor/SoPreferences.h>
33#include <Inventor/nodes/SoNode.h>
34#include <Inventor/helpers/SbFileHelper.h>
35#include <Inventor/sys/SoDynamicLibManager.h>
36
45{
46public:
61 static void addPlatformPluginsPath(SbString path = "")
62 {
63 // if the QApplication alraady exists, we can safely assume everything is in order
64 // if there is a qt.conf file, we do not want to apply our library path modifications
65 // as we should trust the qt.conf to do everything that is required.
66 const bool qtconfExists = QFile::exists( "qt.conf");
67 if ( qApp || qtconfExists )
68 return;
69
70 if ( SoPreferences::getString("QT_QPA_PLATFORM_PLUGIN_PATH", "").isEmpty() )
71 {
72 if ( path.isEmpty() )
73 {
74 // Try to guess QT platforms path from Open Inventor binaries path
75 const SbString pluginPath = qtPluginsPath();
76 if ( SbFileHelper::isAccessible(pluginPath) )
77 {
78 QCoreApplication::addLibraryPath( QString(pluginPath.getString()) );
79 }
80 }
81 else
82 {
83 QCoreApplication::addLibraryPath( QString(path.getString()) );
84 }
85 }
86 }
87
89 {
90 const SbString binariesPath = SoDynamicLibManager::getLibraryFromSymbol((void*)SoInventorBase::init);
91 const SbString qtPlatformsPath = SbFileHelper::toUnixPath(SbFileHelper::getDirName(binariesPath) + "qtplugins/");
92 return qtPlatformsPath;
93 }
94
104 static float getDevicePixelRatio(QWidget* widget)
105 {
106 if (widget == nullptr || widget->windowHandle() == nullptr)
107 return 1.f;
108
109 return static_cast<float>( widget->devicePixelRatio() );
110 }
111
112};
113
114#endif // SB_QT_HELPER
115
116
static SbString getDirName(const SbString &fullFilePath)
Returns the directory path part of a full path string.
static SbBool isAccessible(const SbString &filename, FileAccess mode=READ)
Returns TRUE if a file is accessible
static SbString toUnixPath(const SbString &path)
Converts a Microsoft Windows path (with '\') to a Unix path (with '/').
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Utilities class ...
Definition SbQtHelper.h:45
static void addPlatformPluginsPath(SbString path="")
When a Qt5 application is run, Qt will first treat the application's executable directory as the base...
Definition SbQtHelper.h:61
static SbString qtPluginsPath()
Definition SbQtHelper.h:88
static float getDevicePixelRatio(QWidget *widget)
Return pixel ratio of the widget.
Definition SbQtHelper.h:104
Class for smart character strings.
Definition SbString.h:202
SoNONUNICODE const char * getString() const
Returns pointer to the character string.
static SbString getLibraryFromSymbol(void *symbol)
Returns the full path of the library that contains the given symbol.
static SoNONUNICODE const SbString & getString(const char *name, const SbString &defaultValue)
Returns the value of the specified environment variable in the Open Inventor environment.