Intellisense window using PYQT4 - qt

Hi I am trying to learn pyqt by writing my own texteditor, using pyQT one of the things i want to have is intellisense/word suggestions. i.e so that as you type in the text editor it offers you suggestions of words that would be suitable. I have a list of words, and i can already generate a list of suggestions. My difficulty is presenting it, I am unable to bring up a window/dialog at the cursor location which shows a list of possible words. So far I have succesfully got QMenu to work, but it is limited as in it has no scrollbars and can only display a limited number of suggestions.
I tried QListWidget, but this displayed a popup window(complete with max,min buttons) this just isn't right, though it did allow me to have scrollbars.
I would like to know what object I should use to display suggestions to a user at the cursor location just like one sees in any good IDE. This is what I am trying to do

After doing some searching, I found that I was thinking about it all wrong.QListview is not what I needed
Scintilla is great, and probably the most appropriate. Thank you rainer
There is a wonderful example in
Sample using QScintilla with PyQt
But that is not all that I found. There is a class QCompleter, which is also quite good, as I can use it with a QTextedit, after a good amount of searching I found. "A text-edit which would help enter long words"
QTextEdit with autocompletion using pyqt
Plenty of documentation in
QCompleter Class Reference

Related

Should I use Qt Widgets or Qt Quick to develop a rich text editor?

I am new to Qt in general, and I have been playing with it to get to learn about it since I have to develop a very specific text editor.
I want to know if anyone could help me understand which one is better (or the most indicated) for the development of a rich text editor. I have worked before with C and C++ but Qt Widgets seems like a very step hill for the time being and I am completely new to javascript in general.
Some of the settings that I would need to implement on the text editor for better context are:
Look for the user to be always connected to internet.
Transfer and receive data from another program.
Grant read only to the opened files and then permission to write on them when a button is clicked.
Has to work on linux and windows.
Needs to look great.
My context:
So far I have done a few little applications and even a little rich text editor on Qt Widgets, but since I was having problems with the GUI implementation that I wanted, I started looking for a way to solve it and found that Qt Quick might be the solution.
I have been trying Qt Quick, and for now on looks great, but I do not know if it has the capabilities to do what I have explained before. Or if it is better to use one or another.
I decided to create a new post since the one that I found looking for something similar is from 2014.
Also, the text editor for now only needs to work on desktop, but in a future might be on other devices and embedded systems.

Treeview for FileSystem with checkboxes in qt

We need a tree view with File system and check boxes in QT. Is there any way to achieve that?
The tree we need would look something like below:
UPDATE:
I am able to achieve it with subclass of QFileSystemModel. Still have few challenges, but at least subclass is working. Below is the code if anyone needs it. Below is the link to the code -
https://drive.google.com/file/d/1qViZ3iEW2pV2th0jQhzneDL14SEhIgS0/view?usp=sharing
The pending work is to apply a wait cursor (or make treeview uneditable when the check/uncheck is taking place).
PS: It will take a lot of time if root node is checked.
Well, all of that can be achieved with minimal customizations of built-in classes, actually those checkboxes is almost the only thing that has to be done yourself.
QFileSystemModel already provides a proper model for displaying the current filesystem contents, it can be subclassed
As for QML, the best demo is already provided by Qt, check the File System Browser Example. This example uses some deprecaded Qt functionality, but still it shows the basic concept.
The modern techniqes can be also found in the answers to the following question: Qt File Browser based on QML
Hopefully, all that helps you, good luck!

How to use custom widget in Qt-Designer

I want to use a custom widget in the GUI-Designer of Qt-Creator IDE.
So i created a class which inherits from Qt's QWidget. It worked to place
it on a QMainWindow programaticaly, but have to do my work in the desiger
where it does not appear as an option in the kist of components.
I googled to find a solution for problem an found an manual on, who guesses, the
Qt doc page ( https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html
and https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html).
I tried to follow it but doesn't work.
Does someone know an other way to do this or can give a hint where i can search
for problems following this tutorial?
Thanks in advance.
Codierknecht
There is a different example in the examples section of the Qt documentation that I think is a lot clearer.
Custom Widget Plugin Example
It was a little unclear to me when reading the tutorial where the Q_EXPORT_PLUGIN2() macro goes, but having full example code and project alleviates that.
If you are like me, the analog clock example didn't do it for you, in which case I found just one better tutorial. It may be on the kde site but I you dont need kde to do it, it just explains how to make the custom widget a plugin so you can add it into Qt Designer, rather than having to code it in, which is the norm when you just add a widget to your project and customize the class. I hope this page helps you like it helped me, get in the right direction of writing a single Qt Designer (or multiple) plugin:
Writing Qt Designer Plugins
If this link ever becomes dead, just do a search for the link itself, usually that will turn up the original page in someone's cache, as they do in the other examples above (the dead links in the above answers that just take you to main area and not to the pages originally intended).

Qt - subclassing to provide an alternative view for a text widget?

Currently, I am in the design phase of a Qt widget like what one would see in a typical hex editor. It seemed simple enough to begin with, but as I dig into its implementation details I’m having some confusion.
Basically, the widget would consist of 3 core components: It will inherit QAbstractScrollArea or QScrollArea to provide scrolling and, in the viewport margin, it will display the file offset of each line. Then there will be two text editors; one with the hexadecimal value of each byte of the file, and one with the plaintext character representation.
I, of course, first checked qt-apps.org for any existing widgets, but a search for “hex” only returned QHexEdit and qPHexEditor, neither of which are very complete. I then considered creating a widget completely from scratch as they had, but felt like there should be a more elegant solution. Qt already has much text-editor functionality built into QTextEdit and QPlainTextEdit; why reinvent the wheel?
Now, while the “plaintext view” would be as simple as using a QPlainTextEdit with a fixed-width font and a width of 16 characters, the “hex view” is giving me a headache. I’ve been poring over QTextEdit, QAbstractTextDocumentLayout, etc., trying to figure out a way to present the desired appearance. For those who have never used a hex editor, it should function like so: – Using a fixed-width font, widget should be the width of 47 characters – Widget should display 2 hexadecimal characters per byte, with a blank space between bytes—-16 bytes per line
Since that thought, I’ve been trying to figure out how to subclass any related classes to provide the desired formatting. Unfortunately, the text editing classes don’t seem to follow the model/view framework as closely as I’d hoped, so deriving a new “view” for it doesn’t seem easy. Ideally, the widget would function like so:
One document/model for both the “hex” and “plaintext” views. Editing either view would adjust this model and update the other view appropriately. Signals/Slots at its best.
Because QTextEdit and QPlainTextEdit already provide much of the functionality needed (visible cursor, selections, undo/redo, native look and feel, etc), it would be ideal to re-use this.
So, does anyone have any recommendations? I appreciate any input on this.
QHexEdit2 is a quite complete editor widget for binary data. It can edit very big files, is available for Qt4, Qt5, PyQt4, PyQt4 with python 2 and 3.
see https://github.com/Simsys/qhexedit2

How to design a text editor in QT?

I want to design a text editor in QT and planning to implement the following basic features,
1) Basic editing features like cut,paste,formatting,indentation etc.
2) Auto completion based on the context.(Based on some xml input file)
3) Syntax highlighting ( based on some xml input file )
Can you please suggest some approaches for the overall architecture/design?
How about:
Application Example
Completer Example or Custom Completer Example
Syntax Highlighter Example
All this things are stored in one single place, in you Qt SDK examples
This post is in 2015. NO DEAD LINKS
As #mosg mentioned.
In the menu bar. Go to Help > Index:
and in the search field look for:
Application Example
Completer Example
QSyntaxHighlighter
That would help you to begin.
If using Python is an option for you, you might find my Qt Text Editor example on GitHub useful. It uses PyQt5 (but you can also use PySide2) to implement a minimal text editor. Some screenshots:
It doesn't do formating, autocompletion or syntax highlighting but should still be a pretty good starting point. Maybe you can use QTextEdit and QSyntaxHighlighter to get these features.

Resources