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 ()
 
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 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().

Normaly QHexEdit works in the overwrite Mode. You can set overwriteMode(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 delets 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 ( QWidget *  parent = 0)

Creates an instance of QHexEdit.

Parameters
parentParent widget of QHexEdit.

Member Function Documentation

void QHexEdit::currentAddressChanged ( qint64  address)
signal

Contains the address, where the cursor is located.

void QHexEdit::currentSizeChanged ( qint64  size)
signal

Contains the size of the data to edit.

qint64 QHexEdit::cursorPosition ( QPoint  point)

Calc cursor position from graphics position

Parameters
pointfrom where the cursor position should be calculated
Returns
Cursor postioin
QByteArray QHexEdit::dataAt ( qint64  pos,
qint64  count = -1 
)

Givs back the data as a QByteArray starting at position

Parameters
posand delivering
countbytes.
void QHexEdit::dataChanged ( )
signal

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

void QHexEdit::ensureVisible ( )

Ensure the cursor to be visble

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

Find first occurence of ba in QHexEdit data

Parameters
baData to find
fromPoint where the search starts
Returns
pos if fond, else -1
void QHexEdit::insert ( qint64  pos,
char  ch 
)

Inserts a char.

Parameters
posIndex position, where to insert
chChar, 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.

Parameters
posIndex position, where to insert
baQByteArray, 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

Returns
true when document is modified else false
qint64 QHexEdit::lastIndexOf ( const QByteArray &  ba,
qint64  from 
)

Find last occurence of ba in QHexEdit data

Parameters
baData to find
fromPoint where the search starts
Returns
pos if fond, else -1
void QHexEdit::overwriteModeChanged ( bool  state)
signal

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

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.

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

Removes len bytes from the content.

Parameters
posIndex position, where to remove
lenAmount of bytes to remove
void QHexEdit::replace ( qint64  pos,
char  ch 
)

Replaces a char.

Parameters
posIndex position, where to overwrite
chChar, which is to insert The char will be overwritten and size remains constant.
void QHexEdit::replace ( qint64  pos,
qint64  len,
const QByteArray &  ba 
)

Replaces

Parameters
lenbytes with a byte array
ba
posIndex position, where to overwrite
baQByteArray, which is inserted
lencount of bytes to overwrite The data is overwritten and size of data may change.
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 opend 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

Parameters
font
QString QHexEdit::toReadableString ( )

Gives back a formatted image of the content of QHexEdit

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.

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

Givs back the data into a

Parameters
iODevicestarting at position
posand delivering
countbytes.

Property Documentation

bool QHexEdit::addressArea
readwrite

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

QColor QHexEdit::addressAreaColor
readwrite

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

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 usefull, whe you show only a segment of a complete memory picture. With setAddressOffset() you set this property - with addressOffset() you get the current value.

int QHexEdit::addressWidth
readwrite

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

bool QHexEdit::asciiArea
readwrite

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

int QHexEdit::bytesPerLine
readwrite

Set and get bytes number per line.

qint64 QHexEdit::cursorPosition
readwrite

Porperty cursorPosition sets or gets the position of the editor cursor in QHexEdit. Every byte in data has to cursor positions: the lower and upper Nibble. Maximum cursor position is factor two of data.size().

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.

QFont QHexEdit::font
readwrite

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

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.

bool QHexEdit::highlighting
readwrite

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

QColor QHexEdit::highlightingColor
readwrite

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

bool QHexEdit::overwriteMode
readwrite

Porperty 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.

bool QHexEdit::readOnly
readwrite

Porperty 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.

QColor QHexEdit::selectionColor
readwrite

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


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