I'm using Gtk to build an application on Linux using Python 3. I'm trying to use a Gtk.HeaderBar. So far it's been working Ok, but it seems that I can't get it to expand it's child widgets. For example:
As you can see above, I've tried putting my Gtk.Entry into the Gtk.HeaderBar, but even with things like Gtk.Entry.set_hexpand(True) it simply refuses to expand. I've even tried putting it inside a Gtk.Box, expanding the Gtk.Box, then adding the Gtk.Entry inside that. Even when I set the Gtk.Entry as a custom title for the Gtk.HeaderBar, this happens:
What's causing this? How can I fix it?
Enabling hexpand only says that you want the widget to be allocated all the remaining space; it does not actually resize your widget. You want the halign property set to GTK_ALIGN_FILL (or whatever it's called in Python) in addition to hexpand.
Check the diagrams on this page for a visual explanation.
You can use Box instead of Headerbar with window.set_titlebar method
Related
I'm using Gtk.Fixed and a viewport putting images that, sometimes, overlaps. How can I set the z-index like in html?
Gtk.Fixed doesn't support setting the z-order. It's not meant for overlapping widgets, so the z-order is arbitrary and probably depends on what order the widgets were added in.
It's not clear from your question what your intention is; if you are purposely overlapping widgets, use Gtk.Overlay instead. If you are not intending to overlap them, then you should use a more versatile container such as Gtk.Grid which will take the widgets' sizes into account.
Like ptomato said, I had to use the Gtk.Overlay. I used an overlay with 3 Gtk.Layout, like layers and it works fine.
I only used the C bindings, but I'll try my best to hopefully answer it correctly for the Python bindings as well.
Generally, since GTK4 you can move around your widget using
widget.insert_before (sibling, parent)
Where you might want to obtain the sibling (which will be in front of your widget) and it's parent first.
The function expects the parent to be the parent of the sibling.
So it can be assumed that:
parent = sibling.get_parent ()
At least within a GtkFixed (but possibly other containers as well), siblings are sorted bottom to top, so the first child is the one that's the furthest to the back. "Inserting before" thereby moves your widget behind.
Be aware though, that according to a maintainer, this should only be used within a custom widget and not on an application scale. This is also mentioned in the API of the functions.
From the documentation however, it's not clear to me if this is considered legal. I doubt that this way is supported. However I also doubt, that GtkFixed keeps any track regarding the children order and therefore, I assume that moving children around within a GtkFixed is fine, although illegal.
Moving the widgets around like this also made my application crash, as long as the inspector is open, just as a heads up.
To iterate through the widgets, bottom to top, you can use sibling = parent.get_first_child() as well as sibling = parent.get_next_sibling()
or alternatively use the iterator defined on Widget.
I use PyQt4 and Python 2.7.9.
My program contains a few QLineEdit objects. The problem is that when the program is launched, one of the QLineEdits is being focused automatically, which causes my placeholder text to disappear.
Is there any way to prevent it, or at least don't let it hide the placeholder text?
Another way is
self.this_widget.clearFocus()
after window has been shown. Only in Qt5 placeholder texts are displayed even with focus. So maybe switch to PyQt5.
You can use setFocus to put the focus on a different widget (although, depending on which widget you pick, you might also need to set the focus-policy first):
self.some_other_widget.setFocusPolicy(QtCore.Qt.TabFocus)
self.some_other_widget.setFocus()
Alternatively, if you use Qt Designer to create the GUI, you could edit the tab-order so that the line-edit is not the first in the chain. This can also be done programmatically using QWidget.setTabOrder.
I am looking to know what is the best practice to make a window which the content changes, but without changing the window. Something like using tabs, but with no tabs, controlled with buttons.
What widget should i use to archive what i need?
And if you don't mind the little off-topic, should it be drawn manually or with a GUI designer like glade?
It is meant to be used within python.
If you can use GTK 3.10, take a look at GtkStack and GtkStackSwitcher. If not, use GtkNotebook and set the show_tabs property to False, then build your own buttons.
I am trying to make a widget exactly like this,
I want mine to be exactly the same (same font, picture, ect). Does anyone know how I can do this? I think it is a wx.ListCtrl but I cant find an example on how to make it look like this.
Can you provide me an example on how to make this widget?
Thanks.
It's a report list. Don't forget to keep a reference to the image list yourself since the bindings are stupid and don't incref it when you assign it to the list.
If the widget brings up different panels when you click on the image, then it's probably a Listbook, not a ListCtrl. Plus those are images from the wxPython demo for the Listbook AND the Toolbook AND the Treebook demos, so I'm guessing it's one of those.
Does anyone know if it's possible to add a label to a single tool in a wx.ToolBar? I've found a global setting but no option to set it for a single tool.
I have a feeling that's a limitation of the native widget. It's an all or nothing affair. You could make the label a part of the image on the tool item though. Or you might be able to do it with FlatMenu which has a Toolbar widget equivalent that's written in pure Python, so you can hack it. See the wxPython demo for an example of its API.