Show QImage information on QTextBrowser

  • Hi,
    I would like to know is there a way we can show Image information such as size, format, aspect ratio from QImage class on QTextBrowser. I have an image viewer desktop application and designated an area on application for showing such image information. Presently I am trying with QTextBrowser to show QImage information but as QTextBrowser uses string to setText, the output from QImage is not string.

    P.S. Any alternative method to QTextBrowser to show image information on my app is also welcome .

  • Lifetime Qt Champion

    Hi and welcome to the forums

    Im not 100% sure what the issue was using TextBrowser as you say

    • as QTextBrowser uses string to setText, the output from QImage is not string.

    So you needed something like
    QString info;
    info = "Image width:" + QString::number( someimage.width() );
    info += "Image height:" + QString::number( someimage.height() );
    to convert from integers to text ?

    Or can you tell abit more about the actual issue?

  • @mrjj Yes, I am looking for something like this. While this works for numbers, can I do something to get QImage::Format, such as
    info = "Image format:" + QString::_____( someimage.format() );
    I am not sure what is return type of "someimage.format()"

    As I wrote, to show image specific information on my application, my first idea went towards QTextBrowser to show as text by converting information from QImage class. Does QT has any other way to show such information for images more efficiently because I could not find any.

    Thanks for quick response...

  • Lifetime Qt Champion


    Its an enum. They are normally just values, but Qt has some tricks.

    You can convert to text like

    QMetaEnum metaEnum = QMetaEnum::fromType<QImage::Format>();
    info +=metaEnum.valueToKey(test.format());

    test is the actual image.

    Qt do not have a ImageInformationWidget.

  • @mrjj Hi,
    I see. I didn't realize enum is a type. This works, can mark this thread as solved.

    Thanks a lot

Log in to reply