#๐ Pyside6 question
147 messages ยท Page 1 of 1 (latest)
@tepid pier
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Are these attributes displayed somehow? What exactly are you trying to make?
I think they are all numbers used to by code that enables the user to expand their events on the apps calendar.
You recommended learning about OOP and I did, I'm not sure if I'm applying the right concepts or the concepts correctly to my app.
my name used to be Aizi
ahh ok yeah I remember you ๐
It's still a bit unclear what you're asking though?
are u sure its not just X and Y coordinates and not a Z?
@tepid pier still there?
Yeah sorry.
Oh I was just using those as examples of variables.
Like I have a variable that tracks how big the widget needs to be (increases as they expand the widget) well I can't have one variable, let's call it x, for all 10+ of them, each widget needs to have their own "x".
That's usually done through the sizeHint of the widget
do you have a custom class for your widget?
@tepid pier ?
Okay, Il keep that in mind next time, I don't, but I had a feeling as I mentioned above I need a class for it, when you say custom, do you just mean the widget having its one class?
Perhaps you might still be misunderstanding how classes are used
Do you understand what an instance is?
@tepid pier ?
These help threads are meant to be active conversations. It's very difficult to help if you disappear after each message
Sorry, I'm multitasking. I do, it's a variable that that accesse a class? Right? I hope thats right ๐๐๐
That's not quite right
the variable is called a handler
A Class is a blueprint/template, and an instance is the actual construction from that blueprint
Ohhh what
do you know what str is?
Yes it's a data type, it's used for things like words
!e
print(str)
:white_check_mark: Your 3.14 eval job has completed with return code 0.
<class 'str'>
Yeah
so str is a class
Oh si
but something like "abc" is an instance of that class
123 is an instance of int class
QPushButton is a class
QPushButton() is an instance of that class
Right, how does this apply with creating a class named class_test and creating an instance like class_ instance = class_test()
As far as using it in the purpose I'm wanting
ok, so when dealing with classes in a pyside gui, we typically inherit our classes from existing pyside classes
Okay
so my main window can inherit from QDialog (or QMainWindow)
Yup
from PySide6 import QtWidgets, QtCore, QtGui
from PySide6.QtCore import Qt
class Window(QtWidgets.QDialog):
def __init__(self):
super().__init__()
app = QtWidgets.QApplication()
win = Window()
win.show()
app.exec()
so here's my very basic Window class
I create an instance like win = Window()
and then I show it
If I want a bunch of widgets with similar functionality but might have slightly different data, I can create a new class for that too
class InfoCard(QtWidgets.QFrame):
def __init__(self, title):
super().__init__()
self.title = title
self.setFrameStyle(QtWidgets.QFrame.Box)
layout = QtWidgets.QVBoxLayout()
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
self.setLayout(layout)
title_label = QtWidgets.QLabel(title)
title_label.setFont(QtGui.QFont('segoe ui', 14))
layout.addWidget(title_label)
here's a very simple class example of that
it's a simple widget that displays a title, and draws a box around the widget
I can create many instances of these
If I have two instances of the same class and have them access a variable. If instance one sets it to "1" and the second one sets it to "2" is the variable 2 or is the variable individual to the instance of the class. (That's what I'm hoping)
it depends on the datatype
How come?
What exactly are you trying to achieve?
because it depends on mutable vs. immutable
class Window(QtWidgets.QDialog):
def __init__(self):
super().__init__()
layout = QtWidgets.QVBoxLayout(self)
for i in range(1, 5):
card = InfoCard(f"Title {i}")
layout.addWidget(card)
look at this update to my Window class
I create 4 instances of InfoCard
they each have a unique title
Okay
so it creates 4 identical widgets, just with the text that's different
What exactly do you want to happen? What change needs to affect what?
Each time the user clicks on the calendar to add another identical widget on the calendar, each one of these carbon copy QWidgets needs to have its own variables that track numbers used by the code for expanding the widget. I need to be able to have variables all named the same thing, because the widgets are carbon copies, but are individually associated with their widget so. Each widget gets their own set of variables.
Did that make sense?
Why are you putting so much extra effort into the size? It should all auto-expand for you
you shouldn't have to manually resize anything just because you add a new widget
Oh no, its not made to resize when you add a new widget, the user can expand the widget to let's say have the event go from 10:am to 5:pm etc
Yk like on a basic calendar app
ahh, so the widget represents a position/event on the calendar
Yeah the widget is something the person puts on their calendar like a party or something and they expand it to set the time frame yk
So when I made the original code it worked fine with one event, with it's set of variables, until I put multiple events on the calendar. Which messed with the set of variables. So I'm like, then each one needs to have their own set of variables when the code carbon copies one onto the calendar.
That starts to get tricky when you're dealing with overlapping widgets and positioning
Yeah it's been tricky
I would either be using custom paint events to draw the calendar events, or perhaps even a QGraphicsScene
it adds a ton of complexity, but you get way more control
Well each event needs to be able to have Qinputfield and stuff so that they can fill it out with details. Back to the variable issue?
No, the main issue is how to display the widget
storing the information in the instance is trivial
You can create custom signals and have your main calendar listen for changes
What else is there other than QWidget? It needs to be able to hold Qinput field, QLabel, a bunch of stuff.
Yeah, but QWidget is great when you need to put a bunch of widgets in a layout
it's not ideal for trying to draw a bunch of overlapping widgets on a calendar
They won't be overlapping, thats not how a calendar works
What if two events are happening at the same time?
Ooohhhh si
Yeah
Honestly that doesn't look to hard, as long as you can set which widget goes on top
This solution is where I'd suggest QGraphicsScene, but it's a completely different workflow than standard QWidgets
Can you interact with stuff on QGraphics scene? Type etc, and access the stuff they type?
When I've already worked so hard on this, what would be the incentive in scrapping it all and starting over with QGraphicsScene? I've spent weeks learning how to do make this
My incentive for most GUI tasks is learning new things
When you spend a month on a single gui, it's likely you've already forgot everything you did at the start
Well it's been slow progress because I have to learn everything as I go
I'm excited about redoing things or moving onto new things so I can implement all the new things I've learned
Yeah, it sounds like you chose something very complicated for your first GUI
which probably wasn't a great idea
Yeah probably
But why is QGraphicsScene superior? It's working so far
Like I'd be throwing away working code
For a different type of working code
No affence
Offence*
but you're mostly at the limit of what you can do with your current setup
if you want to implement exactly what you have in mind, it's not really possible with the way you've currently been going
qgraphics has more control over drawing shapes, interactive shapes, and the exact placement of those shapes
I'm pretty disheartened, how do I avoid spending weeks on a project, then find out Im doing it wrong? When there are so many different ways to do/achieve/create something.
It's unrealistic to expect you're going to create your first project perfectly
use every project as a learning opportunity
I've made 100s of GUI
Yeah I guess
many are not good
Okay
but now I can create GUI very quickly, generally with the right mindset
you didn't even know what classes were when you started this project
which is pretty much a requirement for pyside gui
So I have the lines on the calendar made with Qpaint, will I need to scrap that too to use the QGraphicsScene or can they work together.
If you're already used to working with qpaint, you can try and draw all your calendar events using that way too
otherwise you'd have to scrap it (although the logic would be similar for qgraphics)
Yeah I hate dedicated learning like tutorials and shit, I always want to just get my hands dirty ๐๐
It's something I'm working on
QGraphicsScene is like a window into a drawing canvas
I built this GUI in less than a day, because of how much I've learned from my mistakes
How so? You can't type with Qpaint? They have to be able to fill out the event.
That's the tricky bit, yeah
you wouldn't have a nice way to interact with already created widgets
but qgraphicsitem is immediately interactive and you can emit signals when they are clicked
Sweet
It's going to take time to learn. PySide is MASSIVE
I've been using it for 5+ years now and I still learn new things all the time
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.