PySide text in QLineEdit not editable - python

I making a console like program for my application. I have a QLineEdit that takes up the whole height of the screen, where the user will be able to input the commands. I want to add "prompts" for instance 'hostname:current_dir># ' after the # the user will put the command. I want that prompt to NOT be editable (he can just backspace it away) but still have the user be able to type commands. Any ideas? Or may someone suggest a better way of doing this please?

You could connect a slot to the cursorPositionChanged () signal, check its position, and disable editing with setEnabled(False). You might also want to take a look into QTextEdit, QTextBrowser or QPlainTextEdit, where you could use the setReadOnly method.

Related

How to click on QTextEdit with cursor in PyQT5 code

I have a QTextEdit acting as a input field of sorts so whenever you click the post button, it posts whatever is in that QTextEdit. However after I hit post, the text edit deselects which is annoying to have to keep clicking on it before I type more. Is there a method or way in PyQT5 to click on that text box automatically in my code without having to manually move my mouse?
I looked into QTextCursor but that appears to be more for the actual text inside of the text box instead of the box itself. If there's a way to do this, I would greatly appreciate it, thank you!

QPlainTextEdit checking some condition

I want to create my own very simple editor of .txt files. As in real editors, I want that if you change the file and don't save it yet, the name of file will start with '*' (for example, *some_text_file.txt).
I think that fot this I should check QPlainTextEdit after the file was downloaded to editor and after the user pushed button 'save'. But I don't know how to check QPlainTextEdit without user control, but after some changes. Or maybe there is another way to do it. So, how to do it?
You could use the textChanged signal from the QPlainTextEdit. It indicates when the input text has changed. See:
https://doc.qt.io/qt-5/qplaintextedit.html#textChanged
Roughly, you would do the following:
load the file
display the filename without asterisk
connect the textChanged signal into a slot (function) that will add asterisk to the filename
when the Save button is pressed, remove the asterisk
If you're a Qt beginner, you might want to read about the Qt signal and slot mechanism:
https://doc.qt.io/qt-5/signalsandslots.html

qt5 catch input from qtextedit

I am working on a small application which is basically a serial terminal with some added stuff.
for the terminal window I use the QTextEdit widget and allready overload add and overload some methods. However since this is a serial terminal I don't want the input that the user is typing in the QTextEdit to actually end up there. Most serial communication channels echo back the input that is send to them and I would like to show this in the QTextEdit and not what the user inputs.
The ideal would be I could overload the way QTextEdit handles its input and I work from there.
I have looked online but I can't seem to find what I am looking for. Maybe I am using the wrong search terms
You can set the QTextEdit widget to read-only mode and then just listen for its key events. That way nothing will be displayed in the QTextEdit and you will be able to intercept the keys.
If you subclass QTextEdit and reimplement the keyPressevent, you might want to call the base class implementation inside it. Otherwise you might not get the functionalities that for example page-up/page-down keys provide.

Pygame: Graphical Input + Text Input

In Pygame, how can I get graphical input(e.g. clicking exit button) and also get input from the a terminal window simultaneously?
To give you context, my game has a GUI but gets its game commands from a "input()" command. How can I look for input from the command line while also handling graphics?
I'm not sure if this is possible, but if not, what other options do I have for getting text input from the user?
Thanks in advance.
You can't do that, unless you use the input command in a different thread, but then you have to deal with syncronization (which might be what you want or don't want to do).
The way I'd implement this is to create a kind of in-game console. When a special key (e.g. '\') is pressed you make the console appear, and when your application is in that state you interpreter key pressing not as in-game commands but... well, as text. You can print them in the console (using fonts). When a key (e.g "return") is pressed you can make the console disappear and the keys take back their primary functionality.
I did this for my pet-project and it works as a charm. Plus, since you are developing in python you can accept python instructions and use exec to execute them and edit your game "on fhe fly"

GTK StatusIcon: Coordinates of left-click?

how do I get the x/y-coordinates of a left click in a Gtk StatusIcon?
This is my first GTK app and I'm stuck. Is there any way to get details about the last button event that occurred? Or is it possible to pass those details to the handler function when connect()ing the "activate" callback?
Greets,
Philip
Since the status icon isn't a widget, it's a bit roundabout. You might be able to pass in some kind of widget as part of the user parameter object and get the global mouse position on activate. See here on how you might.

Categories