Tuesday, 19 March 2019

Pyqt5 rendering is different on each platform, what can I do to render them the same?

I have some issues with pyqt5 development as I'm trying making a software that should be used on every platforms (Windows, MacOS and Linux). When I execute the same script on each platform, I get different rendering results. It seems to be mostly due to the font and size of the text which are different on each platform. For instance, the pushbutton on the bottom cannot contain the text for MacOS and Linux platforms. The size of some items are also different (see the pushbutton on the bottom) I'm wondering if their is an easy solution to render the window mostly identical on each platform?

Here are the results on each platform: enter image description here

obtained with this script:

from PyQt5.QtWidgets import *
import sys 

class GUI(QMainWindow):
    def __init__(self, parent=None):
        super(GUI, self).__init__()
        self.parent = parent
        self.setFixedWidth(400)
        self.setFixedHeight(300)

        self.centralWidget = QWidget()
        self.setCentralWidget(self.centralWidget)
        self.mainHBOX_param_scene = QVBoxLayout()
        self.setmarginandspacing(self.mainHBOX_param_scene)

        self.Ident_apply = QPushButton('Blablabla')

        self.GB1 = QGroupBox("Identification")
        self.GB1_layout = QHBoxLayout()
        self.Param_0_l = QLabel('Delay')
        self.Param_0_e = QLineEdit('1')
        self.GB1_layout.addWidget(self.Param_0_l)
        self.GB1_layout.addWidget(self.Param_0_e)
        self.GB1.setLayout(self.GB1_layout)


        self.GB2 = QGroupBox("Identification")
        self.GB2_layout = QHBoxLayout()
        grid = QGridLayout()
        self.GB2_layout.addLayout(grid)

        self.RB_Ident = QButtonGroup()
        self.RB_DL  =QRadioButton('DoubleLayer')
        self.RB_CPE= QRadioButton('CPE')
        self.RB_Ident.addButton(self.RB_DL)
        self.RB_Ident.addButton(self.RB_CPE)
        self.RB_DL.setChecked(True)
        self.Fixed_delay  = QCheckBox('Fixed delay?')
        self.Fixed_delay.setChecked(False)

        self.Param_0_l = QLabel('Delay')
        self.Param_0_e = QLineEdit('1')
        self.Param_1_l = QLabel('I(Rs+2*Rcable)')
        self.Param_1_e = QLineEdit('1')
        self.Param_2_l = QLabel('2*I*Zf')
        self.Param_2_e = QLineEdit('1')
        self.Param_3_l = QLabel('Cdl*Zf')
        self.Param_3_e = QLineEdit('1')


        self.Ident_apply = QPushButton('Apply')
        self.Ident_updatepguess = QPushButton('Update Pguess')

        self.Optim_Ident = QButtonGroup()
        self.Optim_curve_fit  =QRadioButton('Curve fit')
        self.Optim_minimize= QRadioButton('minimize')
        self.Optim_basin_hopping= QRadioButton('basin hopping')
        self.Optim_Ident.addButton(self.Optim_curve_fit)
        self.Optim_Ident.addButton(self.Optim_minimize)
        self.Optim_Ident.addButton(self.Optim_basin_hopping)
        self.Optim_curve_fit.setChecked(True)

        grid.addWidget(self.RB_DL, 0, 0 )
        grid.addWidget(self.RB_CPE, 0, 1 )
        grid.addWidget(self.Fixed_delay, 0, 3 )
        grid.addWidget(self.Param_0_l, 1, 0 )
        grid.addWidget(self.Param_1_l, 1, 1 )
        grid.addWidget(self.Param_2_l, 1, 2 )
        grid.addWidget(self.Param_3_l, 1, 3 )
        grid.addWidget(self.Param_0_e, 2, 0 )
        grid.addWidget(self.Param_1_e, 2, 1 )
        grid.addWidget(self.Param_2_e, 2, 2 )
        grid.addWidget(self.Param_3_e, 2, 3 )
        grid.addWidget(self.Optim_curve_fit, 3, 0 )
        grid.addWidget(self.Optim_minimize, 3, 1 )
        grid.addWidget(self.Optim_basin_hopping, 3, 2 )
        grid.addWidget(self.Ident_updatepguess, 4, 0)
        grid.addWidget(self.Ident_apply, 4, 3, )
        self.GB2.setLayout(self.GB2_layout)

        self.mainHBOX_param_scene.addWidget(self.Ident_apply)
        self.mainHBOX_param_scene.addWidget(self.GB1)
        self.mainHBOX_param_scene.addWidget(self.GB2)
        self.centralWidget.setLayout(self.mainHBOX_param_scene)

    def setmarginandspacing(self,layout):
        layout.setContentsMargins(5,5,5,5)
        layout.setSpacing(5)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = GUI(app)
    ex.show()
    ex.setWindowTitle('Windows')
    sys.exit(app.exec_( ))



from Pyqt5 rendering is different on each platform, what can I do to render them the same?

No comments:

Post a Comment