Build complex layout in a dynamic list/grid - python

I'm building a simple app with python3 and GTK3.0 looking for the correct element for display a layout like the following image
I need display N items this items are load from a database (can be 1000+) and can change (insert, delete, update, etc.) and each item have a complex layout inside (labels, buttons, etc.)
How I can build a layout with a list/grid that dynamically changes.
I've read about GtkTreeView and GtkCellRenderer but i dont know how and other people recommend use GtkBox but how handle a model and update dynamically like ListView/CursorAdapter in android or ListView/Bindings in C#/WPF.
documentation of GTK 3.0 is really poor and does not explain how to extend a widget. another point that the documentation does not explain or at least I have not seen is how to reuse the same element, how to make good use of the resources (memory) when dealing with lots of elements, for example I created a series of widget in glade and I can not use N times. also not possible to create items that are not windows. everything should be within a window. as I can create a different arbitrary element of a window that can be reused.
please when you point me any of the above points, this has an example code can be C #, Python or C + + but it is important to have an example

I've just create a project called 'sqlite-browser' using python3 and gtk. When you display a large number of records in a database, you can use treeview, and add a pager (limit 100/200 records each page). Maybe this project can help you. And here it is: https://github.com/LiuLang/sqlite-browser
This is screenshot:

Related

How can I make QStandardItems in a QTreeView work like buttons opening a new window (submenu)?

I am fairly new to PyQt5 or rather to Qt in general, so sorry if this question is really dumb or basic.
I am assigned working on an application for some rather complex scientific data analysis that uses PyQt5. Now my current task is to create an interface to enter all kinds of parameters in a treelike structure. I use a class TreeView(QWidget) for this purpose, loosely following this guide: http://pharma-sas.com/common-manipulation-of-qtreeview-using-pyqt5/
Now my boss wants that for some of the items in the tree it should be possible to click them just like a QPushButton to open a submenu, in which one can enter some more parameters (could be a QTableView I guess). As far as I know it is not possible to append QPushButtons just like QStandardItems right?
So what would be the best way to do this? Is it even possible?

Is there a list of all QSS properties for QSlider in QT for Python?

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.

Customize QTreeView items

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.

Building reusable components with gtk glade

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.

How can I achieve layout similar to Google Image search in QT (PyQT)?

I'm new to QT. I'm using PyQT for GUI development in my project. I want to achieve this layout in my application. This application searches images from an image database. Google image search layout is ideal for my purpose.
I'm following the book "Rapid GUI Programming with Python and Qt" and I'm familiar with layouts. I guess I need to use a grid layout with each result image in each box of grid. & use vertical layout for (image,Qlabel,Qlabel) inside each grid box.
These are some problems I'm facing.
Importantly, I'm unable to display image. What control/widget do I need? I cannot find anything similar to PictureBox of .NET
How do I seperate these image result by fixed gap like in the image? I'm using Horizontal & vertical spacers but that isn't working?
How to set QLabel a clickable (like hyperlink). I don't want to a open a URL. Just the text should be clickable. So, that when user clicks on the link. I can show more information (like next set of results when he clicks on next page number or a new window with image in fullsize when user clicks on 'view') Do we have some new kind of control for this?
This is another important issue. I'll display the page numbers of results (like shown in figure) & assuming they are clickable. How do I load a new page of results? I mean what is the equivalent of page in QT?
As you can guess. This definitely wont be the first page of GUI. The first page will be exactly like http://google.com (a big logo & text box with button below it). when user clicks the search button. This page will be displayed. Again the same question comes up. How change the pages?
Please give a list of controls I'm going to need for this. Tell me if I'm unaware of something.
1/2.
For displaying the images and labels use a QListWidget with view mode set to QListView::IconMode. However, if you need to customize the display beyond what the QListWidget/QListWidgetItem api can provide you will need to create your own QAbstractListModel and use a standard QListView with it.
Make sure and read Qt's primer on model/view.
As for spacing the images, checkout the spacing property on the list view.
Here is an example from KDE's Dolphin file manager:
3. Use a regular QLabel, but set the contents to be an href.
Example:
edit: Oops I see from your tags you are using PyQt, the following is C++, but should be similar to what you would do in python.
QLabel *linkLabel = new QLabel;
linkLabel->setTextFormat( Qt::RichText )
linkLabel->setText( " Click me! " );
connect( linkLabel, SIGNAL( linkActivated ( const QString & link ) ), .... )
4.
Well, since you are using a Model/View, why bother having page numbers at all? The user will just be able to scroll the view and more pictures will be shown. This is by far the easiest solution as you don't have to do anything once you've got your M/V setup!
However, if you really want to show page numbers it will require more work in your model. For example, have a track the "current page" in the model and only allow access to images on the "current page". Then in your slot connected to the linkActivated() signal tell the model to change pages. I won't go into much more detail as this seriously violates the whole idea behind model/view. The "right way" of doing this would be to subclass QListView and add pagination support, but like I said why not use scroll bars? There isn't any performance hits to doing so.
5. Use a QStackedWidget, addWidget() all your "pages" to it, then call setCurrentIndex/Widget() as needed to switch the pages.
Thoughts:
It seems you are very committed to cloning the look, feel, and behavior of Google Image search, which is fine, but Google Image Search is a web application that uses interaction paradigms that are very different than a normal desktop application (links, pages, etc). You are presumably developing a desktop application, and by trying to emulate the behavior of a web app you will find it difficult as the API just isn't designed to support those sorts of interactions. By all means, it is doable, but you'll have your work cut out for you.
If you are extremely intent on sticking to the web based interaction style, why not code your app in javascript and HTML and toss it in a QWebView?
Try using QListWidget with viewMode set to IconMode. It should do all for you. BUT if you need to customize your data display use QListView with your own/standard model and own delegate for painting

Categories