There is no real problem, I have just a cosmetic problem. Well, first I create a form with Qt Designer. On this form I place a QTreeWidget. We are still in Qt Designer. In QTreeWidget, I make a few entries (parents), and then I also take a few child entries. When I am done, I save the ui-file and then I load this file - using loadUi() dynamically. In this case I use PyQt4. Up to this point no problem.
When I load the form with placed QTreeWidget I want the program to expand all child entries. By default, when I run the program I only see the parent entries. When I want to see the child entries I have to click on the parent entries, but I don't want this.
Is there a way to solve this?
There is an expandAll() method, which QTreeWidget inherits from the QTreeView class. So, after calling loadUi(), just add something like this:
self.treewWidget.expandAll()
Related
I want to use btn1 to send a signal to the slot function of deviceTypeSelect, but btn1 can only be associated with QStackedWidget.
There are two problems.
The first is conceptual: Designer cannot know anything about custom slots that are going to be implemented in a promoted widget, and it even should not. The connection to those slots can only be achieved programmatically, and that's for good reasons: Designer cannot "inspect" (nor it should) the source of the files that will be promoted, and it's also completely possible that one would promote a widget and use different classes with the same design files.
The other problem is technical: the "pages" of multipage widgets like QStackedWidget or QTabWidget cannot be used as signal targets on Designer. I don't know if it's just a missing feature or it's by design (knowing how multipage widget plugins are dealt with I wouldn't bet about the it), but unfortunately it really is not possible.
If you want to connect to standard QWidget slots (setEnabled() etc.), set a dummy boxed layout on the page, and add another QWidget in it, but if you use custom slots, as explained before, those must be manually connected from your code.
I'm working on a PyQt program where I want to be able to have some objects, say shapes, in a 'toolbar' of sorts. I would like the user to be able to click and drag an instance of one of these shapes from the toolbar to a main canvas (a QGraphicsView).
For the toolbar I was thinking of using a QListView which I could populate using a QAbstractListModel. However, I'm not sure how I can make the QListView hold only the icons of the shapes that I want... and second of all, how I can make the object icons draggable onto my main canvas. Any ideas?
If this question contained some specific code examples with an existing direction, I could comment more specifically, but here is just some general points:
Your QListView data does not need to specifically relate to the drag and drop issue, so you can populate it however you want: QListWidget, QListView + model, ../
The important aspect is setting up drag methods on your QListX widget to set up an appropriate QMimeData in the QDrag. This is the important part that transfers the data to the drop site. You can have it send an image, or some reference to some data, for which the receiver can make use of.
Set up a drop event on the graphics view to receive and check the mime type. Lets say you are just sending an image. You can receive it and add a pixmap item to your scene. Or maybe you are sending some internal reference like an id to a dictionary. It can be looked up and the data can be added to the scene in the form you want.
Refer to the general Qt Drag and Drop docs. They are pretty much what you want.
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 want to embed a window into another window, kind of like this:
EDIT: Screenshots deleted, sorry!
That is a wingdows program and was not made with GTK tough.
I tried using plugs and sockets, but apparently I can't put a gtk.Window (a toplevel window) on a plug.
Is it possible? If so, how? If not, what do you think I should do instead?
gtk.Window is derived from gtk.Bin, so it can only contain one single child. This again can be used in the following way:
Load both windows (e.g. from Glade files)
Remove the child from the second window, but save a reference to the child
Add the child somewhere in the first window
The second step would look like this:
childWidget = secondWindow.get_child()
secondWindow.remove(childWidget)
I'm using this approach to add plugin windows as tabs in one of my PyGTK applications. That means main window and plugins can be designed separately in Glade, and also implemented independently. Of course you're free to add the child widget anywhere you want.
I am creating a GUI program in Python/PyQT and would like to know how I can connect an event which happens in a child object to the parent?
For example, if someone clicks a 'Submit' button, how would i trigger something to happen in the parent object (lets say update a QLabel on the parent)
Any help would be greatly appreciated
L
It is done like in C++ Qt by connecting signals to slots, you will find all the information on this page (and here for the old way).
You must connect these methods every time you set new parent (and remove old connections!!)
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qobject.html#connect
(If widget parent change and You still wont that new parent to recive signals)
But if your layout is static just give good names for your widgets. Then connect each signal to callable (any python function) and that function will change QLable.
In this case relation parent children change nothing since you refer to widgets by names not relations.