This is probably a simple question, but I can't find a solution anywhere online. I have been making a Kivy application and I keep on reiterating over the same attributes. Can I assign the widgets to groups, and then format the entire group?
Thanks for any advice.
I don't think you can group widgets like you want, but you can specify attributes of widgets in a .kv file using rules so those attributes don't have to be repeated every time.
Related
I'm trying to delete widgets by their ids. If I use remove_widget multiple times this works, for example:
self.ids.container_box.remove_widget(self.ids.box1)
self.ids.container_box.remove_widget(self.ids.box2)
self.ids.container_box.remove_widget(self.ids.box3)
But, is there an instruction that clear container_box without having to write all these lines?
I also tried:
self.ids.container_box.clear_widget()
But it doesn't work
I've only just started learning to code and i'm using Python 3. I'm making a GUI in PySide2 and have been struggling with customising a slider object. I've managed to bodge some code together to change the shape and size of various components of the QSlider object, but could really use a full list of editable parameters for each objects' stylesheet ideally. The doc.qt.io site either lists every object with a small portion of the changeable parameters and some limited examples, or there is a list of every single parameter on stylesheets from every single object, but doesn't specify if certain properties are exclusive to objects (and some definitely are).
Is there documentation anywhere that lists each object in QT and its associated stylesheet options? The main reason for me making this post is that i was looking for a way to edit a QSlider's handle when it is in a pressed state but cannot find what the parameter for that would be. I managed to find that mouseover is done with "hover" but not much else.
When a window-level event (such as a mouse click or a drag-n-drop) occurs in a Kivy application, it gets passed to the entire widget tree. I have multiple widgets of the same class spread across my UI, and need to know which the event occured over. Although I can filter using self.collide(), once I've done that I need to know WHICH widget it is - i.e. is it the top widget in my UI, or the bottom, or what.
I had intended to do this by giving unique names to the "id" value in the kv file for each relevant widget, then run cases in my code based on that. But I was disappointed to find out that "...note that the id will not be available in the widget instance..."
so what's the best practice for giving each widget a unique ID in the kv lang file that can be reference in code? Certainly I could use object properties, but that seems like overkill. Is there some simpler method?
Just give the widgets an identifying attribute or property. If you wanted a string ID, use a StringProperty. It isn't really clear to me that this app structure is the best way to do solve your problem, but it will work fine.
I'm new to PySide and Qt at all, and now need to create an application which has a tree view with styled items. Each item needs two lines of text (different styles), and a button. Many items are supposed to be in the view, so I chose QTreeView over QTreeWidget. Now I managed to add simple text items (non-styled) to the QTreeView and have almost no idea about how to place several widgets on one item. Could you please give me an example of how to create such design?
I've found some samples on the Internet, that are similar to what I want, but they all are in C++, and it's not obvious how to convert delegates and other things to Python. I'm now really confused about it all...
I'd recomend you use simple QTreeWidget and insert complex widgets with setItemWidget. While Qt's widhets are alien, they are not so heavy to draw, but:
You shouldn't create delegates.
You shouldn't handle events (If you are going to place button in view and draw it using delegates, you had to handle all its events, such as mouseOver, focus changing, etc. It is a lot of work.
I am writing a simple application and am using glade (gtk) for the UI. I need many windows (~10), of which one will open depending upon the command line flags, other contextual stuff etc.
Now, all these windows are pretty much similar, they have 3 top level tabs, the last tab is the same in all, all have a OK and Quit button etc., so I am looking for a way to build these windows in glade. I could copy paste one window and make the changes in that, but I am looking for a better way, that will allow me to reuse the common parts of the windows.
Also, I am using pygtk for loading up the windows.
Design a widget with the common aspects you mention. Wherever you need to implement something different, put a GtkAlignment with an appropriate name. Don't forget to change the alignment and fill values of the GtkAlignment.
In PyGTK you can gtk.Builder.get_object(name) to get access to these empty regions and add the extra components within them (which can also be designed with Glade).
Ok, with the help of detly's answer, I am able to get something working. For anyone who needs it, here is what I did.
main.glade contains the window and all the common cruft that I need to be displayed in all windows. comp.glade contains a window, with a vbox component with the extra stuff I need, lets call it 'top_comp'.
Now, in main.glade, I put a gtk.Alignment component in the place where I need the extra component to load, and call it, say, 'comp_holder'. With the builder I have, I do
builder = gtk.Builder()
builder.add_from_file('main.glade'))
builder.add_from_file('comp.glade'))
builder.get_object('top_comp').reparent(builder.get_object('comp_holder'))
This method seems to work for now, but I don't know if it is the correct way to do this thing.
Any suggestions for the above welcome.