0

I was practicing with PyQt5 and I realized that when I ran the same program in two different displays (monitor and laptop), the widgets appeared differently. I got an error in my command line but when I did this:

set QT_DEVICE_PIXEL_RATIO=0
set QT_AUTO_SCREEN_SCALE_FACTOR=1
set QT_SCREEN_SCALE_FACTORS=1
set QT_SCALE_FACTOR=1
python file_name.py

The error went away but the displays are still different.

Error message: Error message after running the code.

When I run the program on monitor:

When I run the program on monitor

When I run the program on laptop:

When I run the program on laptop

Edit:

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

def clicked():
    print("clicked")

def window():
  app = QApplication(sys.argv)
  win = QMainWindow()
  win.setGeometry(200, 200, 400, 400)
  win.setWindowTitle("Tech with ")

  central = QWidget()
  win.setCentralWidget(central)
  layout = QVBoxLayout(central)
  label = QtWidgets.QLabel(win)
  label.setText("my first label!")
  layout.addWidget(label)

  b1 = QtWidgets.QPushButton(win)
  b1.setText("Click me!")

  win.show()
  sys.exit(app.exec_())

window()

burntchowmein
  • 474
  • 1
  • 4
  • 16
  • 2
    Please edit your question to provide a [mcve]. – G.M. Apr 21 '20 at 17:49
  • @G.M. Thanks for letting me know. i just included my code. – burntchowmein Apr 21 '20 at 17:56
  • The one obvious issue is that you create `b1` as a direct child widget of `win` rather than placing it in a layout: that's not really the way `QMainWindow` is supposed to be used. Instead, try adding `bt` to `layout` *before* adding `label` to `layout`. – G.M. Apr 21 '20 at 18:20

0 Answers0