Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQt5 Full Tutorial
#2
Do you create your examples with a designer?

I think using setGeometry for all widgets is not a good idea.

Shrinking the window has the effect that your widgets are no longer visible.

I changed your ProgressBar Example this way

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
 
def update():
    reset()
    completed = 0

    while completed < 100:
        completed += 0.0001
        prog_bar.setValue(completed)
 
def reset():
    value = 0
    prog_bar.setValue(value)
 
app = QApplication(sys.argv)
win = QMainWindow()
win.setGeometry(400,400,300,150)
win.setWindowTitle("CodersLegacy")
 
prog_bar = QtWidgets.QProgressBar()
prog_bar.setFixedHeight(26)
prog_bar.setValue(0)
 
button = QtWidgets.QPushButton(win)
button.setText("Update")
button.setFixedWidth(80)
button.clicked.connect(update)
 
reset_button = QtWidgets.QPushButton()
reset_button.setText("Reset")
reset_button.setFixedWidth(80)
reset_button.clicked.connect(reset)

prog_barwid = QtWidgets.QVBoxLayout()
prog_barwid.addWidget(prog_bar)

btn_wid = QtWidgets.QHBoxLayout()
btn_wid.addWidget(button)
btn_wid.addWidget(reset_button)

layout = QtWidgets.QVBoxLayout()
layout.addLayout(prog_barwid)
layout.addLayout(btn_wid)

main_wid = QtWidgets.QWidget()
main_wid.setLayout(layout)
main_wid.setFixedWidth(280)
main_wid.setFixedHeight(100)

win.setCentralWidget(main_wid)

win.show()

sys.exit(app.exec_())
Reply


Messages In This Thread
PyQt5 Full Tutorial - by Knight18 - Aug-01-2020, 10:17 AM
RE: PyQt5 Full Tutorial - by Axel_Erfurt - Aug-01-2020, 02:46 PM
RE: PyQt5 Full Tutorial - by Knight18 - Aug-01-2020, 05:03 PM
RE: PyQt5 Full Tutorial - by Axel_Erfurt - Aug-01-2020, 05:49 PM
RE: PyQt5 Full Tutorial - by Knight18 - Aug-02-2020, 12:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020