QAbstractItemView::setIndexWidget as editor - qt

Is there any specific reason not to use QAbstractItemView::setIndexWidget for an editor in a QTreeView?
I am having a hell of a time using QStyledItemDelegate's and setItemDelegateForColumn, with data not showing up in editors, checkboxes not replacing the checkbox from QAbstractItemModel.data(index, role).
The docs say not to use it but not why.

Actually docs do not tell to avoid using it at all, but make decision, based on your application behavior. Here is the quote:
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.
I've highlighted the key words that define in which cases you have to use which approach.

Related

Can I "instantiate" (parametrize) prepared ui form by placing it in another form in Qt designer?

I created a simple form object representing some arbitrary name and value pair:
It's intentionally very simple - any design is to be applied through the CSS styles. Apart from the UI, the form consists of C++ class that handles the data loading and custom property defined in Designer too - the name of the data source (eg. hostname).
So I have two values I need to parametrize:
the Name - the QLabel text
the datapoint - some hostname. This will be later loaded by the C++ class and tell it what data should be loaded
I was Imagine I would be able to create "instances" of my form manually in designer and assign parameters to them. Like in this fictional image:
Don't forget datapoint is the custom dynamic attribute. I am sure the described design can be easily carried out programatically, but I feel like the designer solution will be prettier - provided there's a legit way to do it.
Maybe it's wrong, but the only way I can think of is making your Qt Designer aware of your widget. Something like this.
AFAIK, widget propagation doesn't allow you to edit custom properties without code, so you need a full widget support. My colleagues intentionally do whatever posiible from sources, not IDE& Forms, so that the project becomes more portable, but you are to choose yourself.

Forms vs Tables for editable company profile

I am starting to build an app, using Meteor, that includes user-populated company profiles (including both financial data and text). I will be looking into a datafeed for public company information but much of the information for private companies will be user-populated.
I know I will need to create a form for the user to fill in so that the company information will be captured by the database. However, can I make this same form available to the user to both display the data and to allow them to edit the data in the future? Or do I need to build a separate view using tables for this purpose? My preference is the former, just one screen to create and edit as needed.
Any examples of similar instances would be very appreciated.
Thank you.
This is less of a meteor specific question, rather a general web technology question. Meteor can provide the data in the template of course, and it can offer events to process data and insert/update this to a database. This is the same as any underlying architecture. The question is really how to approach the problem with HTML & JavaScript.
A couple of potential methods:
Write your HTML to display the content in its non-editable form. Then provide an edit button to switch mode. When clicking this button switch on 'contenteditable' for the elements you wish to be edited: http://html5doctor.com/the-contenteditable-attribute/
Also reveal a save button, then process the event through meteor. Use selectors to extract the fields by referencing either designated class names, data attributes or name attributes. It would also be a good idea to alter the appearance of editable elements with a background or outline. The disadvantage here is that it's slightly non-standard and you may have the need for more complex data-types like dropdowns or checkboxes etc.
Create view with a standard form HTML. Style it in a way that shapes the information primarily for display rather than editing, eg. hide form field borders. Provide an edit button that when clicked alters the CSS and reveals form field borders, also reveal/replace elements which need more complex controls like dropdowns, perhaps turn on field labels too and of course a save button. The disadvantage is slightly more complex CSS and JavaScript.

Building Custom TextArea in JavaFX

I would like to build a custom TextArea (or a Text objects...).
Here are the limitations I found in the currently available nodes:
TextArea: provide functionality to apply font styles, select, and "getSelected" text. but it does not allow for applying different style to sub-Strings. A style is applied to the whole TextArea.
HTMLEditor: provides means to apply different styles, but not ways to get what string the user selected.
TextFlow: Allows to program different styles to strings. But it is like a label. Not interactive.
I need something a Text Area where users can type, selected, and my code would know what they selected to give them option to apply font styles to the selected string. So I guess what I need a custom object.
Do you agree? How do I go about that?
It seems like you are waiting, like many of us, a kind of JEditorPane (or StyledText, for those who uses SWT) in Java FX.
For now, there is no component of this kind in Java FX.You can use CodeAreaFX, but the performances are not at the best.
If you ant to use WebView as a text editor, you can get selected text by using javascript.

Classes to use for a flexible image selection/tagging widget in Qt

I'm new with Qt and am looking for advice on how to structure this.
I want a flexible widget that can display a set of images (normally read from a directory but other sources too) and let the user select images with the arrow keys and/or mouse and also apply custom tags.
For example there might be 5 tags defined by the application. A user can press a key to select one, and then a little icon would appear in or near the image preview showing that it was selected for that tag.
Would I need to implement this from scratch via drawing on a QWidget or is there something that would make a sensible base class? Thanks!
I would use a QListView base class, and then subclass QStyledItemDelegate.
There is an example here which might help you.

Using QT to build a WYSIWYG Editor for a Custom Markup Language

I'm new to QT, and am trying to figure out the best means of creating a WYSIWYG editor widget for a custom markup language that displays simple text, images, and links. I need to be able to propagate changes from the WYSIWYG editor to the custom markup representation.
As a concrete example of the problem domain, imagine that the custom markup might have a "player" tag which contains a player name and a team name. The markup could look like this:
Last week, <player id="1234"><name>Aaron Rodgers</name><team>Packers</team></player> threw a pass.
This text would display in the editor as:
Last week, Aaron Rodgers of the Packers threw a pass.
The player name and the team name would be editable directly within the editor in standard WYSIWYG fashion, so that my users do not have to learn any markup. Also, when the player name is moused-over, a details pop-up will appear about that player, and similarly for the team.
With that long introduction, I'm trying to figure out where to start with QT. It seems that the most logical option would be the Rich Text API using a QTextDocument. This approach seems less than ideal given the limitations of a QTextDocument:
I can't figure out how to capture navigation events from clicking on links.
Following links on click seems to only be enabled when the QTextEdit is readonly.
Custom objects that implement QTextObjectInterface are ignored in copy-and-paste operations
Any HTML-based markup that is passed to it as Rich Text is retranslated into a series of span tags and lots of other junk, making it extremely difficult to propagate changes from the editor back to the original custom markup.
A second option appears to be QWebKit, which allows for live editing of HTML5 markup, so I could specify a two-way translation between the custom markup and HTML5. I'm not clear on how one would propagate changes from the editor back to the original markup in real-time without re-translating the entire document on every text change. The QWebKit solutions looks like awfully bulky to me (Learning WebKit along with QT) to what should be a relatively simple problem.
I have also considered implementing the WYSIWYG with a custom class using native QT containers, labels, images, and other widgets manually. This seems like the most flexible approach, and the one most likely not to run into unresolvable problems. However, I'm pretty sure that implementing all the details of a normal text editor (selecting text, font changes, cut-and-paste support, undo/redo, dragging of objects, cursor placement, etc.) will be incredibly time consuming.
So, finally, my question: are there any QT gurus out there with some advice on where to start with this sort of project?
BTW, I am using QT because the application is a desktop application that needs platform independence.
Given that I got no advice here, I decided to go with the QTextEdit approach, although I'm actually using a QTextBrowser that is set to be editable so that I can capture link navigation events. I will be using QTextCharFormat's with the link names set to unique identifiers in order to convert from the QTextEdit back to the custom markup. The QTextEdit supports images already, so I won't have to deal with those.
I think I will hit the biggest roadblocks with the fact that I need to be able to insert/grow/shrink tables whose cells can have Excel-style functionality. I have not yet figured that whole process out.

Resources