#includeint main() { sf::RenderWindow window(sf::VideoMode(800, 600), "My window"); sf::Font font; font.loadFromFile("arial.ttf"); sf::Text text("Hello, World!", font, 30); text.setFillColor(sf::Color::Red); sf::DrawingContext dc(window); dc.draw_text(text); window.display(); return 0; }
#includeThis example uses the Qt library to create an image and draw multiple lines of text onto it. The painter object is used to set the desired font and color, and then the drawText function is used to render the text onto the image. The QTextOption class is used to specify alignment and other properties for the text.int main() { QImage image(800, 600, QImage::Format_RGB32); QPainter painter(&image); painter.setPen(Qt::red); QString text = "This is a long\nmulti-line\ntext."; QRectF textRect = QRectF(50, 50, 700, 500); QTextOption textOption(Qt::AlignLeft | Qt::AlignTop); painter.drawText(textRect, text, textOption); painter.end(); return 0; }