Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Drawing text in QtOpenGLWidget
Forum Updated to NodeBB v4.3 + New Features

Drawing text in QtOpenGLWidget

Scheduled Pinned Locked Moved Unsolved Game Development
1 Posts 1 Posters 416 Views
  • 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.
  • S Offline
    S Offline
    stevereine
    wrote on last edited by
    #1

    I have the following code in the overridden PaintGL() function in my QtOpenGLWidget. It draw the ellipse, but not the text. What do I need to do to make the text visible? Just 2D text for now, that's all I need.

    FYI - I am also using OpenGL drawing functions in this PaintGL() function, and they are all working fine.

    QPainter painter(this);
    
    painter.begin(this);
    
    painter.setRenderHint(QPainter::TextAntialiasing);
    QColor fontcolor = QColor(1,0,0,1);
    QFont font = QFont("Arial",20);
    
    painter.setFont(font);
    painter.setPen(fontcolor);
    painter.drawText(200,500,"hello");
    
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(Qt::black,3,Qt::DashDotLine, Qt::RoundCap));
    painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
    painter.drawEllipse(200, 80, 400, 240);
    
    painter.setFont(font);
    painter.setPen(fontcolor);
    painter.drawText(200,80,"hello, world");
    
    painter.end();
    
    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