Git Product home page Git Product logo

Comments (1)

T-640 avatar T-640 commented on July 17, 2024

I found a solution that does not require any changes to the code. It may be a bit hacky but seems to work well. This example assumes version 5.0 is used.

QComboBox

#include <QCursor>
#include <QComboBox>
#include <QVBoxLayout>
#include <QApplication>

#include <qhexview.h>
#include <qmemorybuffer.h>

// This demonstratets insertion of QWidget into the QHexView.
// What is left out is automatically resizing the inserted widget upon changes in QHexView's size
// and connection of QComboBox with QHexView to change QHexCursor's mode.

int main (int argc, char *argv[])
{
    QApplication application (argc, argv);

    QComboBox* box = new QComboBox;
    // Some cursor needs to be set because there would be
    // problems from switching from text cursor to any other
    // when moving mouse from bottom to this widget.
    box->setCursor(QCursor(Qt::PointingHandCursor));
    box->addItems({"Overwrite", "Insert"});

    QHexDocument* document = QHexDocument::fromMemory<QMemoryBuffer>(QByteArray (128, 0x00));
    
    QHexOptions options;
    options.asciilabel = "";
    
    QHexView hex_view;
    hex_view.setAutoWidth(true);
    hex_view.setDocument(document);
    hex_view.setOptions(options);
    
    QVBoxLayout* layout = new QVBoxLayout;
    layout->setContentsMargins(0,0,0,0);
    layout->setAlignment(Qt::AlignTop | Qt::AlignRight);
    // This seems like a hack,
    // because I am not sure if one is ever supposed to set layout on the viewport widget.
    // But everything appears to be fine.
    hex_view.viewport()->setLayout(layout);
    layout->addWidget(box);

    box->setFixedHeight(QFontMetrics(hex_view.font()).height());
    hex_view.show();

    return application.exec();
}

from qhexview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.