tag:blogger.com,1999:blog-1996293708366722208.post1631395889446127286..comments2024-03-23T05:37:58.487+01:00Comments on The Code Inn: Tutorial: How to make a flat,square and colored button in PyQtPeter Goldsboroughhttp://www.blogger.com/profile/08774224362840554281noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1996293708366722208.post-44812760416985710462015-04-17T22:40:28.889+02:002015-04-17T22:40:28.889+02:00There's a :pressed pseudo-state for CSS which ...There's a :pressed pseudo-state for CSS which is activated when a button is pressed, you can set the clicked style there.There are many more pseudo-states and other properties you can set. Here's the reference for Qt's stylesheet properties and syntax: http://doc.qt.io/qt-5/stylesheet-reference.html<br /><br />You can do almost any styling you want with stylesheets and Qt let's you add custom states and properties so it's very extensible. Moreover, you can easily change the style or "theme" of your application just by changing the CSS file you load the style from. Also, I think it's a good idea to keep the style (the "view") separate from the implementation (the "model"). So it's a really great tool all together.<br /><br />Regarding future Python posts: I usually post tutorials or blog posts that relate to what I'm currently working on, which hasn't been PyQt projects for a while, but that may change. Have you had a look at the PyQt Text Editor tutorial series I published on BinPress? You can find it here: https://www.binpress.com/tutorial/building-a-text-editor-with-pyqt-part-one/143Peter Goldsboroughhttps://www.blogger.com/profile/08774224362840554281noreply@blogger.comtag:blogger.com,1999:blog-1996293708366722208.post-22938845117980103382015-04-17T20:48:37.045+02:002015-04-17T20:48:37.045+02:00Also, now that i got your attention!
Your blog is ...Also, now that i got your attention!<br />Your blog is really interesting, but will you be posting more Python stuff in the future?<br />I want to subscribe, but i'm only interested in the Python/PyQT part! (sadly)<br /><br />Thank you for your time..Anonymoushttps://www.blogger.com/profile/09838832384953478285noreply@blogger.comtag:blogger.com,1999:blog-1996293708366722208.post-84745228871551205192015-04-17T20:32:06.570+02:002015-04-17T20:32:06.570+02:00Thank you very much!
A quick question:
What about...Thank you very much! <br />A quick question:<br />What about the clicked state? Does that remain the same as in your code? <br />Anonymoushttps://www.blogger.com/profile/09838832384953478285noreply@blogger.comtag:blogger.com,1999:blog-1996293708366722208.post-15134227482770946682015-04-17T19:25:36.904+02:002015-04-17T19:25:36.904+02:00For some reason, ::hover works. It's actually ...For some reason, ::hover works. It's actually :hover (only one colon).Peter Goldsboroughhttps://www.blogger.com/profile/08774224362840554281noreply@blogger.comtag:blogger.com,1999:blog-1996293708366722208.post-51206346457900862112015-04-17T18:22:20.597+02:002015-04-17T18:22:20.597+02:00Yes, certainly. As a matter of fact most of the ab...Yes, certainly. As a matter of fact most of the above code for timing and hover detection is quite redundant (I was new to PyQt when I wrote this). You can set a global stylesheet from a CSS file for your application and put all the CSS in there (recommended if you plan to do more customization and styling), or just set it internally in the program as I do above. QPushButtons and most other QWidgets have a ::hover pseudo-state in CSS which you can use to automatically perform the shading for hovered buttons. This stylesheet can be set either for the Main class, which will then effect the class itself and all of its children, or for the entire QApplication, in case you have other classes derived from QDialog or QWidget or whatever floating around in your application. Something like this should get you started (app is the QApplication in main()): app.setStyleSheet("QPushButton{background: blue} QPushButton::hover{background: red}")Peter Goldsboroughhttps://www.blogger.com/profile/08774224362840554281noreply@blogger.comtag:blogger.com,1999:blog-1996293708366722208.post-50011701361388023912015-04-17T18:00:40.666+02:002015-04-17T18:00:40.666+02:00Hello, very nice tutorial but is there a way to ma...Hello, very nice tutorial but is there a way to make it global, instead of specifying a button? Image if you have alot of buttons.<br />Typing them all out would be ineffecient.Anonymoushttps://www.blogger.com/profile/09838832384953478285noreply@blogger.com