QPlainTextEdit for single line of input - qt

I'm using Qt to write a database type program where the majority of inputs will be single lines, not documents of arbitrary length.
Do I understand correctly that QPlainTextEdit is the most appropriate widget for this kind of input?
If so, how do you set parameters for this kind of input? In particular:
Height to the right value to comfortably hold one line of text in the current font, instead of stretching to fill available space.
Enter/cursor-down keys move to next control instead of next line in the document.

Take a look at the QLineEdit class.

Related

Game Maker Studio writing in exactly in the middle of a GUI

I'd like to make a pause screen.
In the game the view follows the character and when paused I want the text to be exactly in the middle of the screen. I am using a draw GUI event to display text where the user can see it.
I was thinking of halving the length and width of the port but could not find a function which gave those numbers.
If there is one, what it is, and if not how can I achieve this?
I think I have solved this.
In the GUI event, I use view_hport[0] and view_wport[0] in order to obtain the total length of the port then halve this number.

How to limit the line numbers of QTextBrowser

I use QTextBrowser to show some execution information. I need to use hyperlinks so I choose QTextBrowser. Sometimes a series of more than 10000 lines will be sent to QTextBrowser per command execution.
.setMaximumBlockCount() is for restrict paragraphs, not for lines.I use one paragraph for a execution.
There is no way to limit html "br"-lines with QTextBrowser functions. You have to implement it yourself, e.g. by count each "br" right before insertHtml() and remove extra lines.

Technology of WinHex

I am going to create Win Hex like application in Qt. I want to know which widget should I use for creating hex display area. I have to open hard disk in it so it would be a very large number of lines for displaying 500 GB of disk.
So, which widget can handle this large number of hexadecimal lines?
I have started to do it in QWidget's paint event but the height of QWidget is in integer so number of lines could not be greater than the range of integer.
So, should I use QTextEdit or QPlainTextEdit?
You use wrong way. Consider to use QAbstractItemModel + QTableView. Your model can use "virtual window". It means that your model holds only small piece of data which will be loaded on demand.

Fastest way to draw 1024x1024 dots on screen

I am developing a program that must calculate a color of each point on a 1024x1024 picture using a special algorithm. The color of a point represents some value. So each point is independent of other points and must be drawn separately. I do not have to refresh the picture too frequently. Actually, I need to display it only once.
What is the fastest approach to drawing separate pixels in Qt?
Can I get some sort of "screen memory" and write all the picture as an array of 4-byte sets, representing each pixel as 4 bytes in that memory?
The QImage class is optimized for pixel manipulation. You can instantiate one with the requred size and then either set the pixels individually setPixel, or access the raw data and manipulate them in place via bits(). Just be sure to use the correct format (e.g. RGBA values or color indices for 8-bit images)
The fastest solution may be to create a QImage, manipulate it (set the pixels) and then get Qt to draw it.
The QImage class is for fast IO, from the manual:
The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.
The QImage class supports several image formats described by the Format enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.
There is information on pixel manipulation in the Detailed Description section.
To display it the simplest way would be to convert it to a pixmap with QPixmap::fromImage and then put it in a label with QLabel::setPixmap.
For more control, you could sub-class QWidget, overload the paintEvent, and draw the QImage with a QPainter with QPainter::drawImage.
You might try to use an OpenGL widget and the glDrawPixels function.

What is the maximum number of lines a TextArea control can hold?

I have an app that has text appended to a TextArea (TA). It automatically scrolls to keep the recent line added in view. Over time, this could be a lot. Do I have to worry about this? Is there an upper limit? And, if so, how can I prune the oldest lines of text?
There's nothing in the documentation, but if it gets too big you could run into memory issues. But we're talking collosal here.
It's easy enough to remove oldest lines using the slice() method

Resources