QHexEdit
|
#include <qhexedit.h>
Public Slots | |
void | redo () |
void | undo () |
Signals | |
void | currentAddressChanged (qint64 address) |
void | currentSizeChanged (qint64 size) |
void | dataChanged () |
void | overwriteModeChanged (bool state) |
Public Member Functions | |
QHexEdit (QWidget *parent=0) | |
bool | setData (QIODevice &iODevice) |
QByteArray | dataAt (qint64 pos, qint64 count=-1) |
bool | write (QIODevice &iODevice, qint64 pos=0, qint64 count=-1) |
void | insert (qint64 pos, char ch) |
void | remove (qint64 pos, qint64 len=1) |
void | replace (qint64 pos, char ch) |
void | insert (qint64 pos, const QByteArray &ba) |
void | replace (qint64 pos, qint64 len, const QByteArray &ba) |
qint64 | cursorPosition (QPoint point) |
void | ensureVisible () |
qint64 | indexOf (const QByteArray &ba, qint64 from) |
bool | isModified () |
qint64 | lastIndexOf (const QByteArray &ba, qint64 from) |
QString | selectionToReadableString () |
QString | selectedData () |
void | setFont (const QFont &font) |
QString | toReadableString () |
Properties | |
bool | addressArea |
QColor | addressAreaColor |
qint64 | addressOffset |
int | addressWidth |
bool | asciiArea |
int | bytesPerLine |
qint64 | cursorPosition |
QByteArray | data |
bool | hexCaps |
bool | dynamicBytesPerLine |
bool | highlighting |
QColor | highlightingColor |
bool | overwriteMode |
QColor | selectionColor |
bool | readOnly |
QFont | font |
QHexEdit is a hex editor widget written in C++ for the Qt (Qt4, Qt5) framework. It is a simple editor for binary data, just like QPlainTextEdit is for text data. There are sip configuration files included, so it is easy to create bindings for PyQt and you can use this widget also in python 2 and 3.
QHexEdit takes the data of a QByteArray (setData()) and shows it. You can use the mouse or the keyboard to navigate inside the widget. If you hit the keys (0..9, a..f) you will change the data. Changed data is highlighted and can be accessed via data().
Normally QHexEdit works in the overwrite mode. You can set overwrite mode(false) and insert data. In this case the size of data() increases. It is also possible to delete bytes (del or backspace), here the size of data decreases.
You can select data with keyboard hits or mouse movements. The copy-key will copy the selected data into the clipboard. The cut-key copies also but deletes it afterwards. In overwrite mode, the paste function overwrites the content of the (does not change the length) data. In insert mode, clipboard data will be inserted. The clipboard content is expected in ASCII Hex notation. Unknown characters will be ignored.
QHexEdit comes with undo/redo functionality. All changes can be undone, by pressing the undo-key (usually ctr-z). They can also be redone afterwards. The undo/redo framework is cleared, when setData() sets up a new content for the editor. You can search data inside the content with indexOf() and lastIndexOf(). The replace() function is to change located subdata. This 'replaced' data can also be undone by the undo/redo framework.
QHexEdit is based on QIODevice, that's why QHexEdit can handle big amounts of data. The size of edited data can be more then two gigabytes without any restrictions.
QHexEdit::QHexEdit | ( | QWidget * | parent = 0 | ) |
|
signal |
Contains the address, where the cursor is located.
|
signal |
Contains the size of the data to edit.
qint64 QHexEdit::cursorPosition | ( | QPoint | point | ) |
Calc cursor position from graphics position
point | from where the cursor position should be calculated |
QByteArray QHexEdit::dataAt | ( | qint64 | pos, |
qint64 | count = -1 |
||
) |
Gives back the data as a QByteArray starting at position
pos | and delivering |
count | bytes. |
|
signal |
The signal is emitted every time, the data is changed.
void QHexEdit::ensureVisible | ( | ) |
Ensure the cursor to be visbile
qint64 QHexEdit::indexOf | ( | const QByteArray & | ba, |
qint64 | from | ||
) |
Find first occurrence of ba in QHexEdit data
ba | Data to find |
from | Point where the search starts |
void QHexEdit::insert | ( | qint64 | pos, |
char | ch | ||
) |
Inserts a char.
pos | Index position, where to insert |
ch | Char, which is to insert The char will be inserted and size of data grows. |
void QHexEdit::insert | ( | qint64 | pos, |
const QByteArray & | ba | ||
) |
Inserts a byte array.
pos | Index position, where to insert |
ba | QByteArray, which is to insert The QByteArray will be inserted and size of data grows. |
bool QHexEdit::isModified | ( | ) |
Returns if any changes where done on document
qint64 QHexEdit::lastIndexOf | ( | const QByteArray & | ba, |
qint64 | from | ||
) |
Find last occurrence of ba in QHexEdit data
ba | Data to find |
from | Point where the search starts |
|
signal |
The signal is emitted every time, the overwrite mode is changed.
|
slot |
Redoes the last operation. If there is no operation to redo, i.e. there is no redo step in the undo/redo history, nothing happens.
void QHexEdit::remove | ( | qint64 | pos, |
qint64 | len = 1 |
||
) |
Removes len bytes from the content.
pos | Index position, where to remove |
len | Amount of bytes to remove |
void QHexEdit::replace | ( | qint64 | pos, |
char | ch | ||
) |
Replaces a char.
pos | Index position, where to overwrite |
ch | Char, which is to insert The char will be overwritten and size remains constant. |
void QHexEdit::replace | ( | qint64 | pos, |
qint64 | len, | ||
const QByteArray & | ba | ||
) |
Replaces
len | bytes with a byte array |
ba | |
pos | Index position, where to overwrite |
ba | QByteArray, which is inserted |
len | count of bytes to overwrite The data is overwritten and size of data may change. |
QString QHexEdit::selectedData | ( | ) |
Return the selected content of QHexEdit as QByteArray
QString QHexEdit::selectionToReadableString | ( | ) |
Gives back a formatted image of the selected content of QHexEdit
bool QHexEdit::setData | ( | QIODevice & | iODevice | ) |
Sets the data of QHexEdit. The QIODevice will be opened just before reading and closed immediately afterwards. This is to allow other programs to rewrite the file while editing it.
void QHexEdit::setFont | ( | const QFont & | font | ) |
Set Font of QHexEdit
font |
QString QHexEdit::toReadableString | ( | ) |
Gives back a formatted image of the content of QHexEdit
|
slot |
Undoes the last operation. If there is no operation to undo, i.e. there is no undo step in the undo/redo history, nothing happens.
bool QHexEdit::write | ( | QIODevice & | iODevice, |
qint64 | pos = 0 , |
||
qint64 | count = -1 |
||
) |
Gives back the data into a
iODevice | starting at position |
pos | and delivering |
count | bytes. |
|
readwrite |
Property address area switch the address area on or off. Set addressArea true (show it), false (hide it).
|
readwrite |
Property address area color sets (setAddressAreaColor()) the background color of address areas. You can also read the color (addressaAreaColor()).
|
readwrite |
Property addressOffset is added to the Numbers of the Address Area. A offset in the address area (left side) is sometimes useful, whe you show only a segment of a complete memory picture. With setAddressOffset() you set this property - with addressOffset() you get the current value.
|
readwrite |
Set and get the minimum width of the address area, width in characters.
|
readwrite |
Switch the ascii area on (true, show it) or off (false, hide it).
|
readwrite |
Set and get bytes number per line.
|
readwrite |
Property cursorPosition sets or gets the position of the editor cursor in QHexEdit. Every byte in data has two cursor positions: the lower and upper Nibble. Maximum cursor position is factor two of data.size().
|
readwrite |
|
readwrite |
Property defines the dynamic calculation of bytesPerLine parameter depends of width of widget. set this property true to avoid horizontal scrollbars and show the maximal possible data. defalut value is false
|
readwrite |
Set the font of the widget. Please use fixed width fonts like Mono or Courier.
|
readwrite |
That property defines if the hex values looks as a-f if the value is false(default) or A-F if value is true.
|
readwrite |
Switch the highlighting feature on or of: true (show it), false (hide it).
|
readwrite |
Property highlighting color sets (setHighlightingColor()) the background color of highlighted text areas. You can also read the color (highlightingColor()).
|
readwrite |
Property overwrite mode sets (setOverwriteMode()) or gets (overwriteMode()) the mode in which the editor works. In overwrite mode the user will overwrite existing data. The size of data will be constant. In insert mode the size will grow, when inserting new data.
|
readwrite |
Property readOnly sets (setReadOnly()) or gets (isReadOnly) the mode in which the editor works. In readonly mode the the user can only navigate through the data and select data; modifying is not possible. This property's default is false.
|
readwrite |
Property selection color sets (setSelectionColor()) the background color of selected text areas. You can also read the color (selectionColor()).