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.
Related
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().
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.
I have in my application a larger textbox and offer user the possibility to enter text on several rows like this:
first piece of text
second piece of text
and so on...
Each row is a distinct piece of data that has a significance. The thing is I would like to use ajax auto complete extender functionality after the user types a certain character on a row, such as #, and filter the records in the database according to the first letter the user typed after #, moment when the auto complete suggestion list would appear. For example, third piece of text #Action1, means that after the user typed A he would be prompted with a list of values to choose from.
There are several items of concern for me: first, it is possible to use autocomplete extender only for part of the text in the textbox, and second does it work like this for multiple rows (i.e. one time - in each line behaviour)? Regarding its position, I guess I have no other choice than at the bottom of the textbox it refers to, despite I would have liked it to appear below the # symbol.
Thank you very much.
Update: I found something similar to what I am looking for here: Twitter-style autocomplete in textarea, but the author only explained briefly his solution. Any help much appreciated, thx!
Each row is a distinct piece of data that has a significance.
Why are you using a textarea then, and not multiple <input> fields?
Sounds to me like your error in UI design lies right there already, so the rest of my answer is rather theoretical; I probably won’t go into more details as the sensible fix for your problem is the one above.
first, it is possible to use autocomplete extender only for part of the text in the textbox,
Why shouldn’t it be? Cursor position in a textarea for example is readable (although it requires some working around cross-browser issues).
and second does it work like this for multiple rows (i.e. one time - in each line behaviour)?
So long as the line breaks are “hard” ones (made by the user themselves, using enter/return), splitting the actual textarea content by "\n" to have each row as a single value is no problem.
Regarding its position, I guess I have no other choice than at the bottom of the textbox it refers to, despite I would have liked it to appear below the # symbol.
You could try to roughly measure the #’s position, by line and col number it is on, and match that to the character width and line height, when using a monospace font. For other fonts, some more “magic” might be required to measure the actual width of the previous text before the # character.
I have created a Meteor package for this, which allows both free text and multiple autocomplete sources. Meteor's data model allows for fast multi-rule searching with custom rendered lists. If you're not using Meteor for your web app, (I believe) you unfortunately won't find anything this awesome for autocompletion.
https://github.com/mizzao/meteor-autocomplete
See the link for pictures of how it works. Fork, pull, and improve!
I've got a QTableView for which I want to display the last column always in edit mode. (It's a QComboBox where the user should be able to always change the value.)
I think I've seen the solution in the Qt documentation, but I can't find it anymore. Is there a simple way of doing it?
I think I could archive this effect by using openPersistentEditor() for every cell, but I'm looking for a better way. (Like specifying it only one time for the whole column.)
One way to get the automatic editing behaviour is to call the view's setEditTriggers() function with the QAbstractItemView::AllEditTriggers value.
To display the contents of a given column in a certain way, take a look at QAbstractItemView::setItemDelegateForColumn(). This will let you specify a custom delegate just for those items that need it. However, it won't automatically create an editor widget for each of them (there could in principle be thousands of them), but you could use the delegate to render each item in a way that makes it look like an editor widget.
There are two possibilities:
Using setIndexWidget, but Trolltech writes:
This function should only be used to
display static content within the
visible area corresponding to an item
of data. If you want to display custom
dynamic content or implement a custom
editor widget, subclass QItemDelegate
instead.
(And it breaks the Model/View pattern…)
Or using a delegate's paint method. But here you have to implement everything like enabled/disabled elements yourself.
The QAbstractItemModel::flags virtual function is called to test if an item is editable (see Qt::ItemIsEditable). Take a look at Making the Model Editable in the Model/View Programming documentation.
I can't see an easy way to do this, but you might be able to manage by using a delegate. I honestly don't know exactly how it would work, but you should be able to get something working if you try hard enough. If you get a proper delegate, you should be able to set it on a whole view, one cell of a view, or just a column or row.