#๐Ÿ”’ Need help with PyQt6

19 messages ยท Page 1 of 1 (latest)

trail charm
#

I just started using PyQt6, and im struggling with certain parts of it :

  • for my custom window class, should I extend QWidget or QMainWindow ?
  • how should I make a custom "frame" widget (what class should it extend) ? I'd like it to be stylesheet-able, like a button, add a layout, child widgets, etc ...
  • concerning layouts, how do I make a widget dimensions folllow the window's dimensions (only one at a time for exemple, stick to the sides) ?
  • How do I make the previously stated "frame" widget follow the window's dimensions ? I'd like to make a layout for a borderless window with a top bar, and a frame for the window content (or is there a better way to do it ?)

I have a few more questions but I think that's good enough for now

fading ravineBOT
#

@trail charm

Python help channel opened

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.

dusty geyser
# trail charm I just started using PyQt6, and im struggling with certain parts of it : - for m...

You could inherit from either QWidget or QMainWindow depending on the facilities you need from each. QWidget is more generic while QMainWindow accounts for things typical to a main window (like toolbars, status bars, and what not).

Your widgets should follow your layout's dimensions as long as they're part of that layout and have the appropriate size policy. As long as the layout is applied to the window/widget, it should follow that widget's dimensions.

(and yes, that is generally the way this sort of layout is done, see this PythonGUIs article for reference)

trail charm
dusty geyser
trail charm
#

like a rectangle I can apply a style to, and put things in

dusty geyser
#

Ah, then yeah, use a widget for that.

trail charm
#

Ok, I probably made a mistake when I tried to apply a style sheet to it, becaues it wasn't showing anything

dusty geyser
#

QWidgets can be styled. Although sometimes, if you're styling the background, you might need to specify an additional attribute: widget.setAttribute(QtCore.Qt.WA_StyledBackground, True)

#

!paste If you're trying to style something else and it doesn't work, feel free to send an example.

fading ravineBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

trail charm
#

actually, one question I had is about styling button states :
I tried to do the following:

fading ravineBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

trail charm
#

Button {background-color: rgba(16, 16, 19, 255);}
Button:hover {background-color: rgba(189, 89, 89, 255);}
Button:pressed {background-color: rgba(174, 174, 174, 255);}

#

but it wouldn't work unless I put a border thing in it :

CloseButton {
background-color: rgba(16, 16, 19, 255);
border: none;
}
CloseButton:hover {background-color: rgba(189, 89, 89, 255);}
CloseButton:pressed {background-color: rgba(174, 174, 174, 255);}

#

the hovered state would just be the default style

dusty geyser
#

I'm unable to reproduce that one, whether there is a border or not doesn't seem to affect anything on my end (also, I'll assume you didn't specify the # at the start of the object names due to discord's markdown, otherwise, that should be there)

fading ravineBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.