1

I have QGridLayout in which I insert QLCDNumber as follows:

self.mainLayout.addWidget(display, 0, 0, 1 , 5)

Everything is quite fine but the digit (0 by default) is 'moving' from center to right while window scaling. Can someone give me a hint how to prevent QLCDNumber from scalling and to align text inside it to the right?

TomKo1
  • 214
  • 2
  • 14

1 Answers1

0

Try it:

import sys
from PyQt5.QtCore    import *
from PyQt5.QtWidgets import *

class Window(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.lcd = QLCDNumber() 
        self.lcd.setFixedSize(150, 70)               # Set the size you want
        self.lcd.display(12345)      

        centralWidget = QWidget()                         
        self.setCentralWidget(centralWidget)

        self.mainLayout = QGridLayout(centralWidget)
        self.mainLayout.addWidget(self.lcd, 0, 0, Qt.AlignRight)  # Set the alignment option
        self.mainLayout.addWidget(QTextEdit("TextEdit..."), 1,0)
        self.mainLayout.addWidget(QPushButton("Button"), 2,0, Qt.AlignCenter)

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

enter image description here

S. Nick
  • 12,879
  • 8
  • 25
  • 33