Dax89 / QHexView

A versatile Hexadecimal widget for Qt5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Size of text rectangles not calculated correctly

Ebiroll opened this issue · comments

image
As you can see from image the width of the texts are not correct.

I just try to set the document from a file.
QHexView *pcntwgt = dynamic_cast<QHexView >(centralWidget());
QHexDocument
document = QHexDocument::fromFile(fileName);
pcntwgt->setDocument(document);

OK, So maybe it is a font issue on Linux.
I solved the issue with this patch.

QHexView::QHexView(QWidget *parent) : QAbstractScrollArea(parent), m_document(NULL), m_renderer(NULL), m_readonly(false)
{
//this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);
this->setFont(font);

It looks like a Qt bug:

The workaround is more or less the one posted by you:

if (fixedFont.fixedPitch() == false) { // workaround for QTBUG-54623
   fixedFont.setFamily("monospace");
}

I can add it to the widget...thanks for reporting!

OK. It looks like it fixed the Issue.
It would be good to have some simple examples for this widget.
i.e. I am trying to set the cursor to an offset.

QHexView *pcntwgt = dynamic_cast<QHexView *>(centralWidget());
    QHexCursor* cur = pcntwgt->document()->cursor();
    int reminder=offset%16;
    cur->moveTo(offset/16,reminder,0);

Does not work. :-( Maybe some kind of repaint() is required....

Actually,
I added an emit positionChanged(); in the QHexCursor::moveTo function, then it worked as I expected.

void QHexCursor::moveTo(int line, int column, int nibbleindex)
{
 ...
    emit positionChanged();
}