Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Draw text in an image without a QApplication
Forum Updated to NodeBB v4.3 + New Features

Draw text in an image without a QApplication

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daviddoria
    wrote on last edited by
    #1

    To draw text in an image, I usually use a QPainter. This method requires that a QApplication be available. However, I am trying to write this function in a library so that it can be called from a Qt program or from a non Qt program (just using some bits of Qt as library functions, rather than necessarily using it for a GUI).

    Is there a way to do something like this:

    @#include <QApplication>

    #include "form.h"

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

    QPixmap pixmap(20, 20);
    QColor red(255,0,0);
    pixmap.fill(red);

    QPainter painter(&pixmap);

    QFont font("", 6); // arbitrary (default) font, size 2
    painter.setFont(font);

    painter.drawText(QPointF(10,10), "test"); // bottom left corner of the text seems to start at this point
    pixmap.save("test.png");

    return 0;
    }
    @

    but without a QApplication?

    Thanks,

    David

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      You can try to instantiate QApplication instance in the thread in your dll and do the work there, maybe it will work.(works for QNAM for example). But in general it is not allowed and unsupported.

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved