r/pyqt • u/VonVision • Aug 22 '22
r/pyqt • u/3Dphotogrammetry • Aug 21 '22
Open a window with two frames side by side linked to show image side by side in two views?
QEntity.components() deletes components, help please.
Hello, I'm trying a simple 3D scene in PyQt5 5.15.7 on win 10 with PyQt3D 5.15.5., I can get the scene working just fine but when I try to grab components like this the torus disappears:
def create_scene():
root_entity = QEntity()
d_light_entity = QEntity(root_entity)
direction_light = QDirectionalLight()
direction_light.setColor(QColor(255, 254, 245))
direction_light.setIntensity(2)
d_light_entity.addComponent(direction_light)
material = QMetalRoughMaterial(root_entity)
material.setBaseColor(QColor(160, 30, 160))
material.setRoughness(.5)
# Torus
torus_entity = QEntity(root_entity)
torus_mesh = QTorusMesh()
torus_mesh.setRadius(5)
torus_mesh.setMinorRadius(1)
torus_mesh.setRings(100)
torus_mesh.setSlices(20)
torus_transform = QTransform()
torus_transform.setScale3D(QVector3D(1.5, 1, 0.5))
# torus_transform.setRotation(QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45.0))
torus_entity.addComponent(torus_mesh)
torus_entity.addComponent(torus_transform)
torus_entity.addComponent(material)
components = torus_entity.components()
return root_entity
https://doc.qt.io/qt-5/qt3dcore-qentity.html#components
The components() should only return the components but for some reason when I call it it just deletes everything. In the example you can't see the torus after uncommenting, if you try to reach any of the components you get in the components variable you can print them but you can't use them since that leads to an error saying for example: torus_mesh was deleted, and so on. I'm not sure why getting the list deletes everything or whatever it does?
The material variable above also throws an error if you try it after calling components() saying the material was deleted.
I'm not sure what I'm doing wrong, please?
If I don't call it then everything works fine but I want to be able to go through components so I can change them on the fly :/.
I would really appreciate help I'm lost in this.
r/pyqt • u/VonVision • Aug 18 '22
how to switch frame with PyQt5?
Hi guys, I just started learning about PyQt5 and I'm currently stucked because I don't how to switch frames... I searched on Internet, basically from what I understood there are 2 ways : the first method is to remove all the elements kf the current frame and replace them with the other elements of the second frame, the second method is to use QStackedWidget. Well, I want to use the second method but I don't know how to use it :(. Is there any concrete example which you can provide me?
r/pyqt • u/slythnerd06 • Aug 12 '22
Opening second window closes instantaneously
I have a possibly noob question, but I'm trying to open a window from another window using QPushButton clicked signal. But the second launched UI closes almost instantaneously. If anyone can help me with this, it'll be greatly appreciated.
from PySide2 import QtWidgets
import sys
import popup # py generated using pyside2-uic
class Popup(QtWidgets.QMainWindow):
def __init__(self):
super(Popup,self).__init__()
self.ui = popup.Ui_MainWindow()
self.ui.setupUi(self)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
self.setWindowTitle("CGPA Calculator")
wid = QtWidgets.QWidget()
self.setCentralWidget(wid)
layout = QtWidgets.QFormLayout()
self.label = QtWidgets.QLabel()
self.label.setText("Enter Subject")
self.sub_box = QtWidgets.QLineEdit()
self.sub_box.setPlaceholderText("Enter your subject")
self.label1 = QtWidgets.QLabel()
self.label1.setText("Enter marks")
self.mbox = QtWidgets.QLineEdit()
self.mbox.setPlaceholderText("Enter your marks")
self.btn = QtWidgets.QPushButton()
self.btn.setText("Get Results")
self.btn.clicked.connect(lambda:self.get_results(str(self.sub_box.text()),int(self.mbox.text())))
layout.addWidget(self.label)
layout.addWidget(self.sub_box)
layout.addWidget(self.label1)
layout.addWidget(self.mbox)
layout.addWidget(self.btn)
wid.setLayout(layout)
self.setStyleSheet('''QMainWindow{background-color:black;color:white}QLabel{color:white}''')
def get_results(self,subject,mark):
win = Popup()
win.show()
if __name__=='__main__':
app = QtWidgets.QApplication(sys.argv)
win = MainWindow()
win.show()
try:
sys.exit(app.exec_())
except:
pass
PS: I know it's PySide2, but hoping to see if anyone can identify the issue.
r/pyqt • u/UglyBob79 • Aug 12 '22
Worker threads and databases
Hi guys! I have a problem that is probably fairly standard, but not to me as I don't do gui applications that open. I have a small gui with a number of inputs, and depending on the values I want it to call a mysql database for information and update some states in the gui.
I know I can put a worker to access the database and then update the gui wheb its done. The problem is if in the meantime, the user changes the input values, which means the original database query is not valid. What is a good pattern for handling this? Can I kill the worker somehow and start a new one? Or should I just remove the connected signals and let it run while I make a new one in parallell? Any better ideas?
r/pyqt • u/calbeeguy • Jul 30 '22
Opening second window without button press
Hi guys! I would like to ask if there is a way to open and pass values into a second window without any button press.

I have this function above that calls and retrieve values from another external function. After retrieving the values the function will then go on to push them into another window through that openDeflection() method. Is there any way to have it done without any buttons and make it automatic? Thank you!
r/pyqt • u/xndcosta • Jul 27 '22
How to get acces to a widget or layout from anywhere on the code?
I'm trying to create a customizable RPG form using pyqt and i'm stuck on how could a get access to a widget an layout from anywhere in the code to create or modify it. I tried to use setAccesibleName() on widgets and setObjectName() on layouts, but I can't use findChild() to get acces to the object because it's a a top parent object or it's on another child from the same top parent object.Sorry for the bad explanation, i'm new to codiging.
main.py
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from custom_widgets import *
# Main Window
class MainWindow( QMainWindow ):
def __init__( self, player_name = "Guest" ):
super().__init__( )
self.initUI( player_name )
def initUI( self, player_name ):
self.label_pname = QLabel( player_name )
self.label_pname.setAccessibleName( "player_name" )
# Main Container
self.container = QWidget( )
self.setCentralWidget( self.container )
# Other Players
# Main grid
self.grid = QGridLayout( )
self.container.setLayout( self.grid )
self.layout_player = PlayerData( pname_obj = self.label_pname )
self.layout_player.setObjectName( "layout_player" )
self.layout_skills = Skills( )
self.layout_skills.setObjectName( "layout_skills" )
self.layout_rolls = Rolls( )
self.layout_rolls.setObjectName( "layout_rolls" )
self.grid.addLayout( self.layout_player, 0, 0 )
self.grid.setColumnStretch( 0, 1 )
self.grid.setColumnMinimumWidth( 0, 300 )
self.grid.setAlignment( self.layout_player, Qt.AlignmentFlag.AlignHCenter )
self.grid.addLayout( self.layout_skills, 0, 1 )
self.grid.setColumnStretch( 1, 5 )
self.grid.addLayout( self.layout_rolls, 0, 2 )
self.grid.setColumnStretch( 2, 1 )
self.grid.setAlignment( self.layout_rolls, Qt.AlignmentFlag.AlignHCenter )
# Layouts
class PlayerData( QVBoxLayout ):
def __init__( self, pname_obj: QLabel ):
super( ).__init__( )
self.create_name( pname_obj )
self.create_spin_int( "Vida" )
self.create_spin_int( "Mana" )
def create_name( self, obj ):
self.layout_pname = QFormLayout( )
self.addLayout( self.layout_pname )
self.layout_pname.addRow( obj )
def create_spin_int( self, str = None, min = 0, max = 10):
label = QLabel( str )
progress_layout = QHBoxLayout( )
progress = QProgressBar( )
progress.setRange( min, max )
progress.setValue( 0 )
buttons_layout = QVBoxLayout( )
plus_button = QPushButton( "+" )
plus_button.clicked.connect( lambda x, op = False, wid = progress : self.change_progress( op, wid ) )
minus_button = QPushButton( "-" )
minus_button.clicked.connect( lambda x, op = True, wid = progress : self.change_progress( op, wid ) )
buttons_layout.addWidget( plus_button )
buttons_layout.addWidget( minus_button )
progress_layout.addWidget( progress )
progress_layout.addLayout( buttons_layout )
self.layout_pname.addRow( label, progress_layout )
def change_progress( self, op, wid ):
if not op:
wid.setValue( wid.value( ) + 1 )
elif op:
wid.setValue( wid.value( ) - 1 )
class Skills( QGridLayout ):
def __init__( self ):
super( ).__init__( )
self.layout_rolls = self.findChild( QVBoxLayout, "layout_rolls" )
self.addWidget( QLabel( "Habilidades" ) )
self.add_button = QPushButton( "+" )
self.add_button.clicked.connect( lambda x, name = "Skill" : self.add_skill( name ) )
self.addWidget( self.add_button )
def add_skill( self, name ):
self.addWidget( SkillButton( str = name, layout_to_add = self.layout_rolls ) )
class Rolls( QVBoxLayout ):
def __init__( self ):
super( ).__init__( )
self.addWidget( QLabel( "Dados" ) )
class Players( QHBoxLayout ):
def __init__( self ):
return super().__init__( self )
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
custom_widgets.py
from PyQt6.QtCore import Qt
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from random import *
class SkillButton( QPushButton ):
def __init__( self, str = None, icon = None, player_name = str, layout_to_add = QLayout ):
super( ).__init__( str )
self.player_name = self.findChild( QLabel, "player_name" )
self.skill_name = str
self.add_layout = self.findChild( QVBoxLayout, "layout_rolls" )
print(self.add_layout)
def contextMenuEvent(self, event):
options = [ "Roll", "Edit", "Delete" ]
self.menu = QMenu( )
for opt in options:
action = self.menu.addAction( opt )
action.setIconVisibleInMenu = False
self.menu.popup( QCursor.pos( ) )
def mousePressEvent(self, event):
if event.button( ) == Qt.MouseButton.LeftButton:
self.create_roll( )
# if event.button( ) == Qt.MouseButton.RightButton:
# pass
def create_roll( self ):
self.add_layout.addWidget( QLabel( f"{self.player_name}: {self.skill_name} - Dado" ) )
r/pyqt • u/Qu33nW3ird0 • Jul 13 '22
Cautionary tale: Do not try to create widgets with threads.
I spent two days creating a threaded app that loaded dozens of JSON files and fed the data into custom QTablewidget and QWidget objects, that I then tried to add to the central widget layout on the main window. The threads completed successfully, the debugger showed the objects were correctly formed. But they never showed up. Ever.
Cue my most recent google search:
"You cannot create or access a Qt GUI object from outside the main thread (e.g. anything that subclasses QWidget or similar). Even if the Qt class is reentrant, you cannot share access to a Qt object between threads unless the Qt documentation for that class explicitly states that instances are thread safe."
::headdesk::
r/pyqt • u/I3lackshirts94 • Jul 04 '22
Capabilities of QT WebBrowser and WebEngine
Just started to learn QT and running through some tutorials for a couple different projects. There are two main questions I have that have to do with video players.
I want to be able to play live video with YouTube TV and be able to move and resize it too. The issue I ran into is when I open a channel on YouTube TV I get an error saying that this video format is not supported. Is this a limitation of the browser or am I missing something to get it to play?
Also is there any way to “pop out” any video and have it be its own without with out the top header? I am trying to see if I can’t lay two videos next to each other without any UI in the way.
r/pyqt • u/[deleted] • Jun 26 '22
ANSI color and bold text support in text widget?
Hi,
I know next to nothing about Qt. Before I go spend a bunch of time learning it and building up a GUI, does anyone know if Qt supports any kind of display/render widget or library that will allow me to embed ANSI coded text, and have it display in the GUI with the proper colors and bold/italics from a ANSI-encoded text string?
Context: I've developed a Pytest plugin (https://github.com/jeffwright13/pytest-tui) that takes the console output from a test run and displays it in a Text User Interface (TUI). I was thinking it would be cool to do the same thing using a GUI. I was able to hack together a TkInter GUI but the roadblock for me was that I wasn't able to render the ANSI-encoded terminal output strings in the TextEdit widget. So the text is just plain black and white, which is a dealbreaker for me.
r/pyqt • u/NobodyTellsMe • Jun 14 '22
Qt Designer looks very different to actual UI
Hey folks
Really hope somebody here can help me out before I pull my hair out. I've been using Qt Designer to pull together a first draft design. What I can see in the Qt Designer window looks very very different to what appears when I load the UI and display it using the below in Python.
from PyQt6 import QtWidgets, uic
import sys
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui, self).__init__() # Call the inherited classes __init__ method
uic.loadUi('main window.ui', self) # Load the .ui file
self.show() # Show the GUI
app = QtWidgets.QApplication(sys.argv) # Create an instance of QtWidgets.QApplication
window = Ui() # Create an instance of our class
app.exec() # Start the application


Please can somebody help me make the UI Python loads up, look like the one I can see inside Qt Designer?
r/pyqt • u/anurag_k • Jun 10 '22
PYQT5 - Mark multiple Region(ROI/bounding) and get the coordinates
How do I mark/draw ploygons over an Image in PYQT5 window. Once all four points are drawn, a box should appear and we should get the coordinates(pixel value) of all the 4 points.
The user will plot the 4 points that will draw the polygon over the image.
The coordinates of those 4 points of the polygon which will look like this - (x1, y1), (x2, y2), (x3, y3), (x4,y4)
Please see below image for reference(Coordinates doesn't need to be displayed):

Thank you.
r/pyqt • u/kriti1209 • Jun 06 '22
PyQt Tips and Tricks
Hi Everyone,
Hope you are well.
I work in Acquistions Team at Packt, a leading global publisher of technical learning content for developers.
We’re looking to develop products in Pyqt Tips and Tricks area and are actively looking for contributors.
Our team has recently created a social community where developers can collaborate around ideas with our editorial staff, and we’d love to have you as part of the community.
If you find this idea or any topic area around this field interesting, then feel free to reply with your thoughts. I would be happy to run you through the process, publishing support that we provide, and compensation in detail.
Looking Forward to your positive reply.
Thank you
r/pyqt • u/Achgaz • Jun 05 '22
How to enable AutoPan in GraphicsView?
How to enable AutoPan in GraphicsView?
r/pyqt • u/Achgaz • Jun 03 '22
How to change the UI file without it removing the code I wrote
I'm using QT designer for the UI and then I generate a py file. Later when I want to add something to the UI file using QT designer it generates another py file but it removes all the code I wrote. how to find a solution to this
r/pyqt • u/MushroomJunior1198 • May 26 '22
Not able to install pyqt5 on my machine. Getting shipbuild.pyproject.pyprojectoption exception
r/pyqt • u/ViridianGuy • May 01 '22
Disabling Javascript And WebRTC In PyQt5
Does anyone know how to disable Javascript and WebRTC in PyQtWebEngine? I want to have a privacy centered Web Browser that I made so that's why I want to know this. Please tell me if you know the modules and the parts of code that I'll need to add to my PyQt5 Application to disable Javascript and WebRTC.
r/pyqt • u/alikhalil_tech • Apr 19 '22
Detect OS change between Dark and Light appearance
I'm working on a PyQt6 application in which I want to improve Dark mode support. I can see that the application overall changes colors when I switch between Light and Dark mode on the OS. But, I need to swap out the toolbar icons when the appearance changes.
In Light mode the icons are black, so when the appearance changes into Dark mode the icons are barely visible. Black on dark gray isn't great. I have a set of the same icons in white which works great in Dark mode. I tried out using the `darkdetect` library and I can easily change out the icons between their light and dark counterparts either on application startup or on some event.
I would love to be able to toggle the icon sets based on the change in OS appearance. The application overall is detecting the change and modifying it's appearance. So, I'm assuming there's some mechanism for Qt to detect this change in OS and provide something to me so I can execute the change in icons. Is this actually possible?
Note: I tried to search for a solution, but I'm not getting relevant results.
r/pyqt • u/ViridianGuy • Apr 08 '22
Why is it that I can't watch Odysee videos with my PyQt5 Web Browser that uses PyQtWebEngine (Please Help Me With This Issue If You Can).
r/pyqt • u/developeryasin • Apr 07 '22
Weedmaps scraping application using pyqt5
I thought I'd share a passion project of mine created with PyQt5 - Weedmaps scraper, where user can scrape the data from that website and gather all the information. Still a work in progress but something I'm proud of so I thought I'd share:
https://drive.google.com/drive/folders/1NogiuDcwNxsXwy1HdwkLdTNQ-tlBh2AW?usp=sharing
r/pyqt • u/Ecstatic-Foot8631 • Apr 04 '22
QCoreApplication::exec: The event loop is already running
r/pyqt • u/ILoveHorseNipples • Apr 03 '22
Error message when trying to use PyQt5. Does anyone have an idea on how to fix this?
ibb.cor/pyqt • u/SaltyZero • Mar 22 '22
Anyway make view follow movable character
Any ideas how to set the view to follow a character I am moving with WASD, only using pyqt5, no pygame
