Arranging pyqt combobox in toolbar - python

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.

Related

How to add a "remove button" at the right side of the hovering (or each) item of a wx.ComboBox popup

What I want is a mean to remove an item from the combobox without having to add a separate remove button somewhere else. So I want a remove button to appear at the right side on a combobox dropdown item when I hover over my mouse pointer on it. And, it is also OK if all the items have remove button at the right side and do not need hovering.
The images bellow will illustrate what I am saying [...please ignore my mspaint skils]
[combobox with remove button for hovering item]
https://i.imgur.com/kIMtF3G.jpg
[combobox with remove button for each item]
https://i.imgur.com/iyG23vG.jpg
[NOTE: Sorry, I cannot post images directly because it needs at least 10 reputation to post images.]
[I am new to python and wxpython. So please ignore my ignorance if any. And for the same reason any simple code sample will be greatly helpful.]
Regards.
The wx.ComboBox does not have this feature. The wxPython GUI toolkit uses the target platform's native widgets. If those widgets don't support doing it, then neither does wxPython.
However, wxPython does have custom widgets or you could create your own widget to do this sort of thing.
I also think you could use a context-menu for this task. You would need to right-click to make it work. Another method would be to bind to a mouse event and try to figure out where in the widget you are, but I think that method would be error prone.

Automatic focus on showing deletes the placeholder text of a QLineEdit

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.

Gtk HeaderBar doesn't expand children

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

Assiociate Widgets into Groups, for Hide and Show, wxpython

I have a bunch of widgets and right now I am using Hide() and Show() to each widget individually when I flip through different sections/pages of my program.
Because I did this, You can see each widget leaving/showing one by one (which kinda sucks).
Is there anyway to group all these widgets and then be able to Hide() and Show() this group, to avoid this "one by one" habit?
Try using Freeze/Thaw/Layout when you are showing and hiding the widgets. This way they should all appear/disappear at the same time.
Put your group of widgets organized in a sizer in the same parent container (p.e. a panel) and hide the parent. All the widgets disappear with the parent.
Note that sometimes hiding (for example) buttons or checkboxes is not the best solution. Available functionality for the user can be also modulated using widget.Disable()

How do I prevent Qt buttons from appearing in a separate frame?

I'm working on a PyQt application. Currently, there's a status panel (defined as a QWidget) which contains a QHBoxLayout. This layout is frequently updated with QPushButtons created by another portion of the application.
Whenever the buttons which appear need to change (which is rather frequently) an update effect gets called. The existing buttons are deleted from the layout (by calling layout.removeWidget(button) and then button.setParent(None)) and the new buttons are added to the layout.
Generally, this works. But occasionally, when I call button.setParent(None) on the button to delete, it causes it to pop out of the application and start floating in its own stand-alone frame.
How can I remove a button from the layout and ensure it doesn't start floating?
You should call the button's close() method. If you want it to be deleted when you close it, you can set the Qt.WA_DeleteOnClose attribute:
button.setAttribute(Qt.WA_DeleteOnClose)
Try calling QWidget::hide() on the button before removing from the layout if you don't want to delete your button.

Categories

Resources