I display some rich text contents using a subclass of QTextEdit.
Some editors - especially code editors & IDEs offer a possibility to scroll beyond the last line all the way until the last line gets to the top of the view.
I'd love to be able to do the same thing using QTextEdit. Is this somehow possible? I've been reading the doc but could not find anything.
Thank you.
I never had used QTextEdit that way, but maybe you can solve your problem with scrollToAnchor(QString arg) (which ensure the 'arg' presented in text will be visible), or ensureCursorVisible().
Related
I'm using RichTextFX to implement a commandline interface. What this means is that only the last line of text should be editable, while the previous content should be readonly.
Is there a way to mark a given span as readonly? If not, what is the best way to solve this problem?
Note that I eventually will want to allow other parts of the content to be editable, and not just the last line, so I'm really looking for a generic solution.
I am just learning Qt. I want to show line number of QPlainTextEdit. I found this link http://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
and it worked. But now I want QPlainTextEdit to show line number with other controls on the form as in the image below.
Thanks!
The example from doc.qt.io that you've cited does exactly what you are asking. They subclassed QPlainTextEdit and extended it accordingly. If you just need line numbers, simply delete extra functionality from that example.
I have reached an impass which means I have to spend many hours doing something in a very tedious way because I can't work out a way to do it quickly, here is my problem.
In flash if I make a button that consists of a rectangle and a text field then make it all a button symbol, if I then copy the symbol to multiple instances on screen and change the text in one of them, it changes in all of them because I am changing the symbol.
How can I overcome this, perhaps with actionscript? I tried writing.
button1.text1.text = "test change button text"; on the main canvas (and giving one button a name of button one and the text field within it text1) but it doesn't work.
The only thing I found that works was to make multiple symbol copies of the button but then if I want to change the colour or dimensions of all the buttons it takes ages.
Is there a better way? Using actionscript 2 perhaps, or just some property of the button to allow individual text?
I attempted your situation... and I didn't run into your problem. Text boxes are individual values, provided that the text box is dynamic or input
I think that what may solve your problem is checking what kind of text boxes you are working with. Look in the properties panel; does it say "dynamic"?
I need to make a QLineEdit with non-editable word blocks.
For instance, imagine I drop a word (that actually represents a value) in a QLineEdit.
I would like to write normally on the QLineEdit, BUT if I try to move the cursor inside a word it would move over it, ie, place the cursor at the end/begining of the word.
Also, I would like the word to always show a certain highlight over it, with different colors (to emulate a box that would wrap it).
Any ideas on how to do this? Would a QTextArea be better for this? I was thinking of a QLineEdit because it would actually be inside a QTableWidget cell, so I think it may have more or less the same capabilities, am I wrong?
UPDATE I found these two functions that actually might be helpful for QLineEdit: cursorWordBackward() and cursorWordForward(), so this might help move over the words. Anyone has examples of this?
UPDATE 2 As QLineEdit does not support rich-text, the "highlight" feature I required can only be achieved with a QTextEdit. This has other issues: QTextEdit does not have the functions I mentioned in the first update above, and I don't know if it is possible to put a QTextEdit inside a QTableWidget cell.
QLineEdit can contain only plain text and certainly can't do this. I was thinking about QTextEdit, it can display HTML. But looking at the documentation, I realized that there is no way to insert non-editable block in QTextDocument (which is used by QTextEdit). I think there is no simple solution.
You can try to implement it manually. Catch textChanged() and cursorPositionChanged() signals of QTextEdit, analyze its content and cursor position and modify them if user moved the cursor into non-editable block or changed its content.
Maybe you could achieve this by using an inputMask...
Does anyone know of a TextArea component with autocomplete? I understand Flextras.com's Autocomplete can be reskinned as a TextArea but wouldn't know where to begin.
If you just wanted to auto complete on each word, similar to (Ctrl-Space) in most IDEs, then you could try doing it yourself.
I would imagine that you would catch the change event on the text area then do some comparison (something like startsWith) of the characters preceding the carat against some pre-populated collection of words.
Flextras poses a good question, in how do you display suggestions. One idea would be to use a custom context menu, discussed here, containing your suggestions. There's also a decision to be made on when to display it. Do you display it constantly as the user types, or maybe when they use a key combination (Ctrl-Space).
It's an interesting challenge.