Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Should you be using QT for Python as a GUI? Part seven of an eight-part series of blogs |
---|
If you need to build a GUI system in Python, PyQt5 is probably the best choice, but don't take our word for it - read this blog and see what you think.
|
By far the easiest way to attach formatting to the widgets of a form is using a cascading style sheet. Here we have a simple form with absolutely no formatting:
The form looks drab, but CSS will sort this out.
For the title at the top of the form saying that CSS is great, we've added this dynamic property:
I probably should have mentioned that you can add your own properties to widgets earlier!
You could now create a style sheet - here's mine:
This style sheet sets a default Verdana 14 point font for all widgets, then sets specific formatting for QT labels, push buttons and any widgets to which we've attached the class h1_title.
You can then apply this in your code:
# opens style sheet and returns string of text containing CSS
with open(r"temp.css") as css_file:
css = css_file.read()
# apply CSS
self.setStyleSheet(css)
This is what would appear when you run your form and click on the button:
In retrospect I should have put a bit more effort into making the styles look nice! Notice that the title appears in a different font size, because it has its dynamic property class set to h1_title.
This ability to attach CSS style sheets to GUI forms is a big selling-point to me for PyQt5.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.