self.find_next_ret_act = QtWidgets.QAction(triggered=self.toolButton_5.animateClick)
self.find_next_ret_act.setShortcut(QtGui.QKeySequence("Return"))
self.find_next_enter_act = QtWidgets.QAction(triggered=self.toolButton_5.animateClick)
self.find_next_enter_act.setShortcut(QtGui.QKeySequence("Enter"))
self.toolButton_5.addActions([self.find_next_ret_act, self.find_next_enter_act])
I am using PyQt5 and I was trying to set couple of shortcuts to one tool button but it didn't work except with the QAction workaround but the problem now is that I want to hide the QAction menu that appears when I hold the tool button down, is there any way to do so?
Thanks,
Max
Related
I'm writing a PySide application with a GUI meant for a touch screen. It has a main window that covers 75% of the screen and a 25% vertical panel that has buttons that control the content displayed on the main window (several widgets/screens should appear on the main window).
I've seen several different ways for doing this "split": QFrame, QStackedLayout, QStackedWidget. Being a beginner with PySide/Qt, I couldn't figure out which one is the best way to go for my specific case. Any suggestions or example applications?
QFrame with a QVBoxLayout and specify the stretch factor: (C++ code)
MainWidget main = new MainWidget();
ButtonWidget buttons = new ButtonWidget();
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(buttons);
layout->addWidget(main);
layout->setStretch(0,25);
layout->setStretch(1,75);
form->setLayout(layout);
I have a ctrl+f dialog and when I press the window, it causes the main window to lose focus. Is there a way to have both windows have focus?
Kind of, but not really. Only one window can claim focus on the desktop/operating system level. You want this to be your application or main PyQT object. Then, what you want to do is define a new window type (QObject) that will be treated like a toolbox/dialog within the parent application. This will set a child-like focus attribute. Your application will retain focus on the desktop level, and now you have another inner-focus attribute for windows spawned from within your app.
QtGui QStyleOptionToolBox
StackOverflow: pyqt popup window
I have a custom GTK widget (basically an overlay of HBox over a Cairo surface). I wish to hide it when I click outside the widget in the window. Similar to how menus behave.
I tried using grab_focus and wait for the focus-out-event but the widget doesn't grab focus, I think it's not a focusable widget.[1]
[1] https://developer.gnome.org/pygtk/2.24/class-gtkwidget.html#method-gtkwidget--grab-focus
You might have to set the CAN_FOCUS flag, if you want to use the focus_out event.
But if you want to click outside to hide the widget, as is necessary with menus, then you have to connect to events of the area below the widget. You could connect to the button_press event of the window, taking care not to stop event propagation.
I am trying to connect the click() signal of a button to my own function. The button is in a widget that I created with QT Designer. I load the .ui file with QUiLoader like so:
class MyWidget(QtGui.QMainWindow):
def __init__(self, *args):
QtGui.QMainWindow.__init__(self, *args)
loader = QtUiTools.QUiLoader()
file = QtCore.QFile("pyside_ui_qtdesigner_form_test.ui")
file.open(QtCore.QFile.ReadOnly)
self.myWidget = loader.load(file, self)
file.close()
self.setCentralWidget(self.myWidget)
btn = self.myWidget.findChild(QtGui.QPushButton, "HelloWorldButton")
btn.clicked.connect(self.slot1)
def slot1(self):
print "Received"
Is this the correct way to connect to button clicked() signal? I see that I can wire up signals and slots directly in Qt Designer, but how do I prepare and get to such wire-ups in the code?
Side question: The code above works, but the main window shows in the wrong size. How do I ensure that it appears in the right size? Should I do this with minimum height/width constraints?
Use Signals and Slots Editing Mode for connecting predefined Qt signals directly to predefined Qt slots.
So for "Close" button on a simple dialog, you can just drag a connection from the button to the dialog, select the clicked() signal and the reject() slot, click "OK", and there would be nothing more to do.
For signals and/or slots you want to define yourself, you do not need to "prepare" anything in Designer beforehand. Everything should be done in your own code.
Your example already demonstrates this fairly well, but the connection could be done much more simply and cleanly, like this:
self.myWidget.HelloWorldButton.clicked.connect(self.slot1)
As for your main window having the "wrong size": it's difficult to tell from the code you've shown, but it may be because you did not set a layout in the widget that you are loading.
BTW: is there a specific reason you're using QUiLoader? Compiling python modules using pyuic4 is much more flexible, and you can learn a lot from the code that is generated.
EDIT
For me, setting a layout on the main form cures the resizing problem you are talking about.
If you don't know how to do that: in Designer, right-click on a blank part of the main form, and then select Layout/Layout in a Grid from the menu (there's also a button on the toolbar for this).
Once you've done that, resizing the form will automatically stretch it to fit the contained widgets.
I edited the .ui file:
Close QT designer
Edit the .ui in the slot/signal area
Run it
I have a QTreeWidget with QComboBoxes inside of it. I would like to be able to hide the combo boxes.
I am getting the QComboBox out of the tree using the itemWidget function. I have tried using setVisible(False) and hide() but neither work. Can anyone explain why this is the case and possibly offer a soultion?
I suspect it has something to do with the QTreeWidget or the QTreeWidgetItems controlling the visibility of its widgets.
Have you tried putting the QComboBoxes inside a layout inside a QWidget, and placing the QWidget in the QTreeWidget?