pyqt5 permanent widget focus - pyqt

in my pyqt5 application, I have a QLineEdit that can have its value changed by both typing and pressing buttons that have advanced actions on the QLineEdit's text.
I have done some research and found the setFocusPolicy, but it does not have a permanent focus option, is there a way around this?
edit: by "permanent focus" I mean that the QLineEdit is always in a focus state where one can type into it, but clicking somewhere else or tabbing does not change the focus to a different widget

musicamante had it right, what I did was add a corresponding *widgetObject*.setFocusPolicy(Qt.NoFocus) line for each of my widgets that could possibly focus
note: I had this import line specifically for the NoFocus constant
from PyQt5.QtCore import Qt

Related

PYQT change clearButton in QLineEdit (w/wht Qt Designer)

Since I updated python from 3.8 to 3.10 (with Linux Ubuntu 22.04), clear button in QlineEdit widget has become an ugly red cross. It was before a nice dark kind of rectangular button with a small cross inside.
I wish I could switch back to the previous clear button without having to create a custom button, because the red cross is kind of disturbing as it seems to indicate an error in what you write in the QLineEdit widget.
Is there a way to do that in Qt Designer or programmatically?
It seems a bit unlikely that just updating Python would affect the icon.
The update probably involved other packages along with it (or they need rebuilding, they were uninstalled due to incompatibilities, etc), so I'd suggest to check that first.
In any case, you can set the icon using a specific stylesheet you could set for the top level window or even the application, so that it will be used for any QLineEdit with the clear button enabled:
QLineEdit > QToolButton {
qproperty-icon: url(/path/to/icon.png);
}
Note that this will override all icons of QLineEdit, including those used for custom actions, so in that case you must explicitly set the object name of the button and use the proper selector in the QSS:
# this assumes that the clearButtonEnabled property is already set,
# otherwise it will crash
lineEdit.findChild(QToolButton).setObjectName('clearButton')
lineEdit.setStyleSheet('''
QLineEdit > QToolButton#clearButton {
qproperty-icon: url(/path/to/icon.png);
}
''')
Also, see this related answer for other alternatives.

Why does a borderless Kivy Window shift content down and to the right?

Using Kivy, I want to remove the default border from the App window (removing the close, minimize and maximize buttons). Based on the Kivy docs, I want to set the borderless value of my Window to True. However, doing so moves the content of my window down and to the right, exposing the black background color on the top and left sides of the window.
Screenshot of Window with borderless=False
Screenshot of Window with borderless=True
In the above images, the white within the window is coming from the Window.clearcolor, and the black in the borderless=True image is what I want to remove, or overlay with the rest of my content.
In the following snippet I have removed all the code that makes up the inner widgets of the kivy App, replacing them with an empty GridLayout to show where the content will be.
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
class MyApp(App):
def build(self):
self.title = 'My App'
Window.clearcolor = (1, 1, 1, 1)
Window.size = (300, 430)
Window.borderless = True # This is what is being changed
return GridLayout()
if __name__ == '__main__':
MyApp().run()
I have read the answers to similar questions regarding removing the default Kivy window border and how to position a borderless Kivy window.
Can anyone help diagnose how to shift the contents of my window back to the upper left corner when borderless is set to True?
Note: This is my first Stackoverflow question, please let me know how to improve it if need be!
Well, I'm not sure what the exact issue was, but after troubleshooting several different things within PyCharm (where my original project files were held), on a whim I tried opening the same project with Sublime and the issue is no longer present. When I run the identical code in Sublime, I get the intended result:
Beautiful! Just how I wanted it. =) I'm sure I somehow goofed up the Kivy settings in Pycharm somehow without realizing it, maybe something with the builder strings? I'm honestly at a loss. But I suppose if by any off chance someone else comes across this, switch up your IDE for a clean slate and give it another go.

How to remove the balls that appear in the kivy window?

I was wondering if it is possible, I believe so, removes the balls that appear in the window of the kivy when I click on it with the right button. It seems to me that it is a pattern, and I see no use.
I think it's a simple thing to solve...
I also have another question, and not to need to post a new question, here goes.
Let's assume I made a kivy window without borders:
from kivy import Config
Config.set('graphics', 'borderless', '1')
Now my doubt. How do I move the window by dragging the mouse?
Place this code at the top of your main .py file:
from kivy.config import Config
Config.set('input', 'mouse', 'mouse,disable_multitouch')
See the documentation.
Just left-click on the ball you want to remove

How to detect, in a QWidget, closing the main window

I know that similar question was already answered, but my case is a little bit different
Case:
I have a QWidget which contains a QLineEdit and a QListWidget
The QListWidget is a FramelessWindow which means that it is not located in the main window but it appears independently (actually it is a dynamically changing list depending on the content of the QLineEdit filed: "filter as you type")
Problems:
When I close the main window, it will not close the QListWidget automatically. After the main window closed, the QListWidget will be still seen. - I could not find event, in the QWidget, which would work for that purpose. The closeEvent(self, event) is never triggered.
When I move the main window the QListWidget will be still stay in the original position. It will not follow the QLineEdit's position. I could not find event, in the QWidget, which would work for that purpose.
Conditions:
I do not want to detect the changes in the main window. I know that the
closeEvent(self, event)
works in the main window, and I could delegate it to the QListWidget.
BUT I want to write an independent widget, which does not depend on the setting in the main window.
Can somebody help me with telling/suggesting how to detect the window close/window move inside a widget?
If you need the code (pretty long ~300 lines), I can copy it here.

PyQt4 Qt Designer making dynamic GUIs

I'm trying to figure out a way of using Qt Designer to make a dynamic GUI. For example, let's say I have a main window with a horizontal layout. I have a push button on one side and an empty area on the other. When I click the button the empty area will be filled with a widget that I've made in Qt Designer. When the button is pressed again the widget will be replaced with another widget that I've made in Qt Designer. Would I have to go about making all my widgets, to fill the empty area, custom widgets?
I've tried setting the parent to the empty are, but on the second change I get this
QLayout: Attempting to add QLayout "" to QWidget "t2", which already has a layout
So then I tried deleting the layout but still see the old widget underneath the new one and the layout is now messed up.
help please
Never mind, figured it out. Simple really. Use QStackedWidget and as for the UIs made in Qt Designer wrap that in a class that inherits from QWidget.

Resources