Make QTreeWidgetItem unique among siblings - python

Is there some way to make sure that updating an existing QTreeWidgetItem or inserting a new one ensures that the item is unique among its siblings based on the value of a single column?
I have tried to do something like this with a QTreeView and my own custom model and have gotten it to work, but some advanced features like moving items with drag and drop are eluding me. I figure, the QTreeWidget and QTreeWidgetItem classes ought to get more of this type of stuff for free and ought to cause me fewer headaches throughout. However, I still need to be able to guarantee uniqueness if I go the QTreeWidget route. Can this be done? If so, how?
NOTE:
I am using PySide, but I marked this question as PyQt as well since most solutions cross over between the two without much fuss.

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.

PyQt display 1 widget in 2 layouts?

I'd like to add QLineEdit/checkbox/button in 2 layouts. So no matter which one I press in which ever window they both do the same thing, update each other as I type and so on.
Is it possible or do I need to create second set of controls and then signal link each other?
Regards
Dariusz
A widget can only exist in one place at a time. You will need to link the two unfortunately. Do yourself a favor and do it properly via a model.
If it were possible for a widget to exist in multiple places, this would lead to a whole lot of problems: cyclic trees, multiple parents, etc.

PyQT Qtabwidget add, remove, hide, show certain tab

I am trying to build a GUI which will:
Load a file with parameters which describe certain type of problem.
Based on the parameters of the file, show only certain tab in QTabwidget (of many predefined in Qt Designer .ui)
I plan to make a QTabwidget with, say 10 tabs, but only one should be visible based on the parameters loaded. Enabling certain tab is not an option since it takes to many space and the disabled tabs are grey. I do not want to see disabled tabs.
Removing tab could be an option but the index is not related to a specific tab so I have to take care of the shift in the indices. And furthermore if user loads another file with different parameters, a good tab should be added and the current one removed.
My questions are:
How to do this effectively?
Is it better to use any other type of widget?
In Qt designer, is it possible to define many widgets one over another and then just push the good one in front. If yes, how? And how to edit and change any of them?
If using RemoveTab, how to use pointers on tabs, rather than indices?
I use PyQt4
Use a QStackedWidget, which is exactly the same as a tab-widget, but without the tab-bar (which you don't need).
This widget is available in Qt Designer. The context menu has several commands for adding/removing pages and so forth. Note that the arrow buttons in the top-right corner are just there for convenience: they won't appear in your application.
Pages can be added/removed at runtime with addWidget/removeWidget:
index = self.stack.addWidget(self.page1)
self.stack.removeWidget(self.page1)
You can access the pages using either indexes or widget references.
I see that this thread is kinda old. But I hope this will still help.
You can use the remove() method to "hide" the tab. There's no way to really hide them in pyqt4. when you remove it, it's gone from the ui. But in the back end, the tab object with all your settings still exist. I'm sure you can find a way to improvise it back. Give it a try!

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.

Categories