Qt supports custom paint events for drawing of widgets through QStyle.
However when using the QStyle you need to specify what type of element you're trying to draw,
i.e, if you want a control element you need to paint it by using QStyle.drawControl(CE_Example, style).
My question is, how is someone who is relatively new meant to understand which method to correctly call, or find which element to paint when I want to perform the actions myself, say for example I want to draw my SpinButton with purple up and down arrows. I tried to google and see if I could find an explanation but could not, so I was wondering if this is common terminology or if it was some jargon used by the Qt community.
Any advice for correctly traversing documentation or anything like that appreciated, maybe I have an incorrect approach.
I eventually found my answer traversing https://doc.qt.io/qt-5/qstyle.html#details
Primitive Element: A primitive element is a common GUI element, such as a checkbox indicator or button bevel.
Control Element: A control element is a part of a widget that performs some action or displays information to the user.
Complex Control: Complex controls have different behavior depending upon where the user clicks on them or which keys are pressed.
Related
Using Python 2.7 and PyQt4.
So I need a way to make a text of the QPushButton editable when click on it, like on QTextEdit.
There is no builtin way to edit a push button in the sense that you have a cursor and can type along.
Probably the easiest solution is to bring up a QInputDialog. If that feels to heavy, you could also place a floating QLineEdit over or next to the QPushButton. Close that on <Enter> and set the typed text to the QPushButton.
If you really want an editable Button, you'll have to subclass QPushButton and implement the desired functionality yourself. To get started with this, you need to reimplement mousePressEvent() for starting your editing mode. Reimplement keyPressEvent() for handling key strokes. If you need to display a cursor, reimplement paintEvent(). I have no particular resource at hand that describes what exactly you have to do, but the terms above should be sufficient to look it up yourself.
Is the equivalent of ToggleButton exist in PyGtk ?
I would like to have a callback like: True or False.
self.liste = gtk.ComboBox(self.liststore)
self.liste.connect("changed", self.result_list)
With this method, the program can't detect if the user clicks again on the same choice.
Thanks
I don't have any specific advice as I haven't used ComboBox much, but I'm pretty sure that what you want to do is possible.
The GTK tutorial says
ComboBox uses a TreeModel (usually a ListStore) to provide the list
items to display.
The basic ComboBox methods are great for simple things, but for more advanced usage you need to play with things at the TreeModel level yourself. To do that effectively, you need to know how they work; fortunately the docs in the tutorial are pretty good: TreeView widget, but also check out the info in the reference manual.
To make the equivalent of a toggle button you can use 14.4.8. Activatable Toggle Cells
I am making a GUI for a script in Python, using PySide Qt. I have a couple of checkboxes in the main window and I was wondering if it is possible to make them dependant to each other. What I mean is that, if I check one of them, all the others should become unchecked. So only one can be checked at a time.
Is there a comfortable way to do this? Otherwise I would just write a function to uncheck the others.
use QButtonGroup to make them as a group and you might want to derive a class from this and override the basic check/uncheck depending on how you want the checkboxes to behave
I recently made a simple notepad-like text editor but now I want to implement things like syntax highlighting certain words and automatic indentation as you type. How could I do this dynamically as the user types. So far everything I've done is event-based so I'm guessing I need to have some sort of loop that constantly checks the contents of the textbox as the user is typing? Is tkinter not suited for this? Appreciate it if you steer me in the right direction as to how I can implement this.
Tkinter is quite well suited to this sort of thing. It's possible to make a very smart text editor if you're willing to put in some effort.
This answer shows how to get the text widget to fire an event whenever something in the text widget changes. It's a little complicated, but fairly foolproof.
If you want something simpler, you can simply bind on <Any-KeyRelease> which will fire an event whenever the user releases a key. You can then use the information in the event object to decide what to do. It won't handle the case where you cut and paste with the mouse, for example, and your binding will fire for arrow keys and other non-inserting keys, which is why I recommend the more complicated solution.
This answer shows an example of using a binding on <space> to do do a simple spellcheck, and also shows a fairly simplistic implementation of a toolbar with a "bold" button.
I´d like to create a program which will react on actions by user in real time. For example there will be three Labels. And when user clicks on one, I want to recolor the border to a different color and the user should be able to "type" a (single) number in this Label. I know about the Entry widget, but Labels are suitable for the whole application.
Thank you for any answers
Your question is too vague to answer precisely, but to specifically address each individual point:
Yes, it's possible to "react .. in real time" -- whenever an event is detected it will be acted upon as soon as possible.
Yes, it's possible to color the border of a widget when an event is detected
Yes, it's possible to type into a label. Though, obviously, the behavior is unusual and may not be what you expect.
I suspect none of those help you solve your real problem, but I have no idea what you're actually trying to accomplish.