QHexEdit: QHexEdit Class Reference

QHexEdit

Public Slots | Signals | Public Member Functions | Properties | List of all members
QHexEdit Class Reference

`#include <qhexedit.h>`

Inheritance diagram for QHexEdit:

## 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

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ QHexEdit()

QHexEdit::QHexEdit | ( | QWidget * | parent = `0` | ) |

Creates an instance of QHexEdit.

Parameters

  parent | Parent widget of QHexEdit.

## Member Function Documentation

## ◆ currentAddressChanged

void QHexEdit::currentAddressChanged | ( | qint64 | address | ) |
| signal

Contains the address, where the cursor is located.

## ◆ currentSizeChanged

void QHexEdit::currentSizeChanged | ( | qint64 | size | ) |
| signal

Contains the size of the data to edit.

## ◆ cursorPosition()

qint64 QHexEdit::cursorPosition | ( | QPoint | point | ) |

Calc cursor position from graphics position

Parameters

  point | from where the cursor position should be calculated

Returns
  Cursor position

## ◆ dataAt()

QByteArray QHexEdit::dataAt | ( | qint64 | pos,
|  | qint64 | count = `-1`
| ) |  |

Gives back the data as a QByteArray starting at position

Parameters

  pos | and delivering
  count | bytes.

## ◆ dataChanged

void QHexEdit::dataChanged | ( |  | ) |
| signal

The signal is emitted every time, the data is changed.

## ◆ ensureVisible()

void QHexEdit::ensureVisible | ( |  | ) |

Ensure the cursor to be visbile

## ◆ indexOf()

qint64 QHexEdit::indexOf | ( | const QByteArray & | ba,
|  | qint64 | from
| ) |  |

Find first occurrence of ba in QHexEdit data

Parameters

  ba | Data to find
  from | Point where the search starts

Returns
  pos if fond, else -1

## ◆ insert() [1/2]

void QHexEdit::insert | ( | qint64 | pos,
|  | char | ch
| ) |  |

Inserts a char.

Parameters

  pos | Index position, where to insert
  ch | Char, which is to insert The char will be inserted and size of data grows.

## ◆ insert() [2/2]

void QHexEdit::insert | ( | qint64 | pos,
|  | const QByteArray & | ba
| ) |  |

Inserts a byte array.

Parameters

  pos | Index position, where to insert
  ba | QByteArray, which is to insert The QByteArray will be inserted and size of data grows.

## ◆ isModified()

bool QHexEdit::isModified | ( |  | ) |

Returns if any changes where done on document

Returns
  true when document is modified else false

## ◆ lastIndexOf()

qint64 QHexEdit::lastIndexOf | ( | const QByteArray & | ba,
|  | qint64 | from
| ) |  |

Find last occurrence of ba in QHexEdit data

Parameters

  ba | Data to find
  from | Point where the search starts

Returns
  pos if fond, else -1

## ◆ overwriteModeChanged

void QHexEdit::overwriteModeChanged | ( | bool | state | ) |
| signal

The signal is emitted every time, the overwrite mode is changed.

## ◆ redo

void QHexEdit::redo | ( |  | ) |
| 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.

## ◆ remove()

void QHexEdit::remove | ( | qint64 | pos,
|  | qint64 | len = `1`
| ) |  |

Removes len bytes from the content.

Parameters

  pos | Index position, where to remove
  len | Amount of bytes to remove

## ◆ replace() [1/2]

void QHexEdit::replace | ( | qint64 | pos,
|  | char | ch
| ) |  |

Replaces a char.

Parameters

  pos | Index position, where to overwrite
  ch | Char, which is to insert The char will be overwritten and size remains constant.

## ◆ replace() [2/2]

void QHexEdit::replace | ( | qint64 | pos,
|  | qint64 | len,
|  | const QByteArray & | ba
| ) |  |

Replaces

Parameters

  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.

## ◆ selectedData()

QString QHexEdit::selectedData | ( |  | ) |

Return the selected content of QHexEdit as QByteArray

## ◆ selectionToReadableString()

QString QHexEdit::selectionToReadableString | ( |  | ) |

Gives back a formatted image of the selected content of QHexEdit

## ◆ setData()

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.

## ◆ setFont()

void QHexEdit::setFont | ( | const QFont & | font | ) |

Set Font of QHexEdit

Parameters

  font |

## ◆ toReadableString()

QString QHexEdit::toReadableString | ( |  | ) |

Gives back a formatted image of the content of QHexEdit

## ◆ undo

void QHexEdit::undo | ( |  | ) |
| 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.

## ◆ write()

bool QHexEdit::write | ( | QIODevice & | iODevice,
|  | qint64 | pos = `0`,
|  | qint64 | count = `-1`
| ) |  |

Gives back the data into a

Parameters

  iODevice | starting at position
  pos | and delivering
  count | bytes.

## Property Documentation

## ◆ addressArea

bool QHexEdit::addressArea
| readwrite

Property address area switch the address area on or off. Set addressArea true (show it), false (hide it).

## ◆ addressAreaColor

QColor QHexEdit::addressAreaColor
| readwrite

Property address area color sets (setAddressAreaColor()) the background color of address areas. You can also read the color (addressaAreaColor()).

## ◆ addressOffset

qint64 QHexEdit::addressOffset
| 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.

## ◆ addressWidth

int QHexEdit::addressWidth
| readwrite

Set and get the minimum width of the address area, width in characters.

## ◆ asciiArea

bool QHexEdit::asciiArea
| readwrite

Switch the ascii area on (true, show it) or off (false, hide it).

## ◆ bytesPerLine

int QHexEdit::bytesPerLine
| readwrite

Set and get bytes number per line.

## ◆ cursorPosition

qint64 QHexEdit::cursorPosition
| 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().

## ◆ data

QByteArray QHexEdit::data
| readwrite

Property data holds the content of QHexEdit. Call setData() to set the content of QHexEdit, data() returns the actual content. When calling setData() with a QByteArray as argument, QHexEdit creates a internal copy of the data If you want to edit big files please use setData(), based on QIODevice.

## ◆ dynamicBytesPerLine

bool QHexEdit::dynamicBytesPerLine
| 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

## ◆ font

QFont QHexEdit::font
| readwrite

Set the font of the widget. Please use fixed width fonts like Mono or Courier.

## ◆ hexCaps

bool QHexEdit::hexCaps
| 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.

## ◆ highlighting

bool QHexEdit::highlighting
| readwrite

Switch the highlighting feature on or of: true (show it), false (hide it).

## ◆ highlightingColor

QColor QHexEdit::highlightingColor
| readwrite

Property highlighting color sets (setHighlightingColor()) the background color of highlighted text areas. You can also read the color (highlightingColor()).

## ◆ overwriteMode

bool QHexEdit::overwriteMode
| 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.

## ◆ readOnly

bool QHexEdit::readOnly
| 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.

## ◆ selectionColor

QColor QHexEdit::selectionColor
| readwrite

Property selection color sets (setSelectionColor()) the background color of selected text areas. You can also read the color (selectionColor()).

The documentation for this class was generated from the following file:

- /media/winni/sda8/working_copy/working_copy/hacking/c++/qhexedit2/src/qhexedit.h