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.
Related
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!
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:
I have come across a problem while using wxPython lately: I want to grey out a whole wx.Menu and I can't find a way to do it. I could disable all the wx.MenuItem instances related to the wx.Menu, but I find it less efficient ergonomically speaking than greying out the menu itself.
The wx.Menu class has a method named Enable() which accepts the 'enable' argument, but its solely use is to enable/disable a related wx.MenuItem and not the wx.Menu itself. Actually, I'm not even sure that what I want can be done.
However, I would be glad to listen to your solutions if you have some.
Enable is just for the menu items. EnableTop should counter-intuitively disable the entire menu. See my old tutorial on menus about half-way down for more info. Here's how I did it:
self.menuBar.EnableTop(0, False)
Note that it's zero-based, so zero is the first menu, one is the second, etc.
I am trying to write a text viewer widget with PyGTK that displays line numbers alongside the main viewing window. Of course I want the line numbers and main window to scroll in sync with each other. I can't figure out how to get this to work, though. Right now I am doing this. TextViewer is a subclass of HBox that creates the two TextViews and packs them into itself under the attribute names linenums and mainview.
self.textviewer = TextViewer.TextViewer(self.toplevel)
sw = gtk.ScrolledWindow()
sw.set_vadjustment(self.textviewer.mainview.get_vadjustment())
sw.set_hadjustment(self.textviewer.mainview.get_hadjustment())
sw.add_with_viewport(self.textviewer)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
If I take out the two set_Xadjustment lines, then the embedded TextViews' scroll_to_mark function doesn't work, which isn't acceptable for my application. With them in, the main text window scrolls twice as quickly as the line number window, and vice versa if I set the ScrolledWindow's adjustments to those of self.textviewer.linenums. I strongly suspect that this is a bug. I also tried setting up the viewport myself and setting its adjustments to those of one of the TextViews, but again the scroll_to_mark functions stop working. How can I synchronize both TextViews to scroll as one, so that any scrolling changes to one of them equally affect the other?
EDIT: Here is the code in my main application where I set up the widget.
self.textviewer = TextViewer.TextViewer(self.toplevel)
sw = gtk.ScrolledWindow()
#These are the lines that toggle between the two problems when (un)commented
sw.set_vadjustment(self.textviewer.mainview.get_vadjustment())
sw.set_hadjustment(self.textviewer.mainview.get_hadjustment())
sw.add_with_viewport(self.textviewer)
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
I'm having difficulty understanding exactly how you've got the two gtk.TextViews packed in the HBox. Are they both packed in separate gtk.ScrolledWindow that are then packed inside of the HBox which is then packed into another gtk.ScrolledWindow(The one mentioned in your post)? From what it sounds like to me, both of these gtk.TextViews are packed in their own gtk.ScrolledWindow within your TextViewer wrapper widget.
If this is the case, a simple solution to your issue, granted that the two gtk.TextViews are the same height(so the line numbers line up with the main view), I suggest simply packing them inside your Hbox without ScrolledWindows. Then you can use your code above, adding them that ScrolledWindow and the viewport will move the two collectively as if they are one widget.
If this isn't your issue, could you please supply some more information about your TextViewer wrapper, and maybe some more sample code?
Also: You may be interested in gtksourceview. With the gtksourceview2 package, you get an instance of the View widget:
import gtksourceview2
view = gtksourceview2.View()
You might want to check how it is implemented in Meld. In particular, the filediff code (search search for sync there).
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.