I am using QTreeWidget with single column. QTreeWidgetItem has multiple childs in some situations. I am updating dynamically, data in every QTreeWidgetItem. Now when I am adding this data to particular child & I am expanding it. But I am unable to set scroll to that particular QTreeWidgetItem.
Is it possible?
Thanx in advance.
Use scrollToItem. You can pass a scroll-hint as the second argument to control how the scrolling is done:
treewidget.scrollToItem(item, QtGui.QAbstractItemView.PositionAtCenter)
Related
I have the following problem, you may help me with:
There exists a GUI, that was created with Glade. The window contains multiple items of the type Gtk.TextView.
My intention is to change the background color of one of these items after clicking on it. Each item is connected with a signal, that is fired to change the color.
The change of the color works fine, because what i get over the widget argument is the expected Gtk.TextView.
The next step I do, is saving the name of the widget gained through get_name() into a label for later use, because as soon as I click on another item the last one should be reset to the former color. Unfortunately, when I want to get this (former) item - using get_object()-Method from Gtk.Builder and saved name as parameter - I get an object of type Gtk.TextBuffer. Now, there is the problem that TextBuffer has no modify_bg/base facility - and no option to change the color.
Is there any way to trace back a TextBuffer's TextView?
Thanks in advance!
Regards
I have made a toolbar in qt designer with a few buttons. I have found some answers on stack that say you can not add a combobox in qt designer. With this I found an example of adding it manually. The method was:
self.combo=QtGui.QComboBox(self.toolBar)
self.combo=insertItems(1,["One","Two","Three"])
However, this puts the combobox all the way on the left ontop of my other buttons. How do I add this to the end? I read the doc that says the QComboBox is QStandardItemModel, which either takes self or a parent. I have tried giving extra arguments like some sort of index but the error says it only takes one argument. How can I specify which location the combobox will go?
Thanks
You added QComboBox as a child of QToolbar. It doesn't belong to any layout, so it doesn't take space in toolbar's layout. You need to use QToolbar::addWidget or QToolbar::insertWidget instead.
self.combo=QtGui.QComboBox()
toolBar.addWidget(self.combo)
self.combo.insertItems(1,["One","Two","Three"])
Note that I've replaced = to . in the last line. It should have been typing error.
I'm writing a GUI program where I want to create several check buttons with text from a list. The problem is that I have many lists, and I therefore want the user to be able to go to the "next page" and see a different set of check buttons based on a different list. However, to do this I need some kind of textvariable in my check buttons so the text is updated every time a user goes to the next page. Though, as far as I know, there is no such option.
Is this possible to do, or do I need to create a separate check button and a separate label with the textvariable in it?
Help would be much appreciated. Thanks in advance!
Only possible approach I can think of is doing config on a checkbutton. Assuming you are using standard tk checkbuton, you can call:
checkbutton.config(text=newtext)
where newtext is the new text, obviously.
Add the call to the callback bound to the next and previous page buttons. If you really need to use a variable, add a property to a class based on checkbutton and modify its setter to call the config function on asignment.
I'm using PyGObject but I think this is a question that could be adapted to all GTK, so if someone know how to do it using C or anything should work in python also.
I have two treeview, Active and Inactive, I load data from a Sqlite database and I can swap and drag & drop items from one to other.
This is just an aestetic thing, if I click on one item on one treeview I want that a previous selected item on the other be deselected.
It appears that nobody had to do something similar because I didn't found anything about it on the net.
At the risk of being too basic (perhaps I misunderstand the problem), to manipulate treeview selections, you use the GtkTreeSelection object returned from GtkTreeView.get_selection. You can attach to signals on this object, change the current selection,etc.
To turn off selection in the other view, you can get its selection mode property and set to GTK_SELECTION_NONE. To turn it back on upon clicking, my thought was that you could catch a grab-focus signal, set the selection mode to single in that view, and set the selection mode to none in the other view:
(connect view-1 'grab-focus
(lambda args
(set-mode (gtk-tree-view-get-selection view-1) "GTK_SELECTION_SINGLE")
(set-mode (gtk-tree-view-get-selection view-2) "GTK_SELECTION_NONE")))
(That code is using the guile-gnome wrapper but the concept should be the same in any language binding.) A problem with this approach is that now in order to make a selection you must click the tree view twice - once to grab the focus, and again to make the selection.
I have a QTreeWidget with what I thought all the proper settings setup in order to be able to reorder items by dragging them around. It can work, at times, but more often than not I drag an item into another one and it either disappears or becomes a child.
Is there anyway to prevent this from happening so you don't lose items you're trying to reorder? I figured you could achieve this within Qt Designer. I have dragDrop mode set to InternalMove and defaultDropAction set to MoveAction, but I'm not even certain of both of those are what I need to be adjusting.
Thanks in advance!
You can add flags to individual tree widget items that control drag and drop behaviour (amongst other things). For instance, to prevent an item being a drop target, try something like this:
item = QTreeWidgetItem(parent)
item.setFlags(items.flags() & ~Qt.ItemIsDropEnabled)
For more details, see: Qt.ItemFlags