Set QButton height - python

I probably should post this in multiple questions.
I need to know two things, I have a simple window that all it has is a button within it, set like so:
self.spherize = QtGui.QPushButton("Spherize")
I'm just wondering how to set the height of this button?
I've tried the following but it didn't work:
self.spherize.setHeight(50)
Also, where can I find propper docs for things like this with example code?

This is PyQT documentation for QPushButton, but it inherits from QAbstractButton and QWidget which has the methods for changing widget size.
The call you want is QWidget.setFixedHeight. So you want something like:
self.spherize.setFixedHeight(50)

Here is the PySide documentation.

Related

Implement a Kivy Button mouseover event

I am making a GUI that will have two buttons. I want to perform a sort of Animation on both of those when someone hovers over them.
Now, I know that using Window.bind(mouse_pos=my_mouse_pos_func) is a workaround since no on_mouse_hover is available for button.bind() like on_press and on_release. But that isn't working for me since I cannot specify which widgets in my screen to bind my function when using Window.bind(). Doing this works in a way but only if I get the cursor in my main window.
I have searched for this a lot and in almost 90% of the results I found people recommeding Window.bind(). And the other 10% are workarounds but were really unclear to me, for e.g workarounds like "listening for mouse events" and stuff like that.
Sorry, as I am being able to provide any code as I am quite clueless as to what to show. If anyone knows any simple workarounds to this, their help will be absolutely appreciated
I use the mentioned Window.bind() in the __init__() method of my app as:
Window.bind(mouse_pos=self.on_mouse_pos)
Then in the on_mouse_pos() method, I use the collide_point() method to determine if the mouse is over any of the Buttons in question:
def on_mouse_pos(self, window, pos):
for butt in self.root.ids.butt_box.children:
if butt.collide_point(*pos):
# do something here
You just need a list of the Buttons you want to check (I use the children of a container).
I know it's an older post, but just a follow-up in case someone (like me) has the same problem and finds their way here over Google. #John Anderson's solution works, but it seems easier to me to define a class for those buttons you want to display the desired behaviour and then use Window.bind() in its __init__(), e.g.
from kivy.core.window import Window
from kivy.uix.button import Button
class MyButton(Button):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Window.bind(mouse_pos=self.on_mouseover)
def on_mouseover(self, window, pos):
if self.collide_point(*pos):
# desired behaviour
That way there's no need to keep the list John mentions.

How to use pyqt widget event() method?

Exactly how do I utilize the various event methods that widgets have? Say I have a comboBox(drop down list) and I want to initiate a function every time someone changes the choice. There is the changeEvent() method in the documentation but It would be great if someone explains to me with a piece of code.
This is a pretty broad question. I recommend checking out the many tutorials on Youtube.com.
However, in your init method, put something like this:
self.ui.charge_codes_combo.currentIndexChanged.connect(self.setup_payments)
In my example, the combo box was placed on a form in Qt Designer. Self.setup_payment is a method triggered by the change in the combo box.
I hope this helps!

PyQt: display QPushButton that looks like the down-arrow button in QComboBox

In PyQt4, I want to present a QPushButton that looks like the down-arrow button in QComboBox. Feasible, and if so, how?
I don't need help getting my new widget-combination acting like a QComboBox (see below). I only want the QPushButton display/graphic to look like the down-arrow button in a QComboBox - and tips/code on how to overlay that graphic (especially if said graphic comes via a file) onto my own QPushButton.
More details, context:
I'm seeking to replace a QComboBox widget with a QLineEdit + QCalendarWidget, because QDateEdit isn't as customizable as I need (I think...). The thought is to place a QPushButton immediately adjacent (on the right-side) of the QLineEdit to make it things look like regular QComboBox as much as possible. Then said button will .exec_() the QCalendarWidget (which is technically wrapped by a QDialog).
Let me know if this doesn't make sense, and I can provide further or clarified context.
You can try a QToolButton with no text and the arrowType property set to Qt.DownArrow. eg: myqtoolbutton.setArrowType(Qt.DownArrow).

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

How to add images/bitmaps to wx.Dialog

I want to add images to wx.Dialog (and then sizer) some like wx.ImageList and display it dynamically.
But I don't want to change already displayed image, I want to add next.
How can I resolve this problem?
I don't think a dialog is a good choice for a growing list of images, but if you have a good argument for that...
Anyway, you should be able to display your images using the wx.StaticBitmap widget. To add another one, use your sizer's Add method, then call the dialog's Layout() method and maybe its Refresh() method. If you plan on displaying many images, then you'll probably want to look at the ScrolledPanel or the ScrolledWindow widgets.

Categories

Resources