Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:15:13+00:00 2026-05-27T09:15:13+00:00

[Note: I prefer PyQt, but an answer for Qt is the same as far

  • 0

[Note: I prefer PyQt, but an answer for Qt is the same as far as I am concerned. I understand both languages.]

Question:

I would like to render a string, for example: ‘Hello world!’ (nothing fancy). I DO NOT want to do this through a proxy, such as QTextEdit or QWebKit. Rather, I want full control of the rendering on a low level – each character. The issues/questions are:

  1. Which widget should I use (for quickest rendereing) QGraphicsWidget?

  2. Given a position (x,y), how do I then render an image of the character on the screen?

  3. The text may span multiple lines. Should I render an image of each character to the screen one by one, or should I first create an ‘image’ of the line, and then render each line (I assume this would aid in the speed of scrolling, as wouldn’t have to recalculate every character, only move the line up or down)? If the latter, how do I create that image?

  4. How would I go about highlighting a selection as the user drags his mouse over it – would I have to rerender the character, or just do some ‘background color’ operation on that position of the screen?

Please, I would appreciate if you could answer in a practical manner – i.e. specific methods/classes/etc. (not just a vague idea like ‘display it’ – but how?).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:15:13+00:00Added an answer on May 27, 2026 at 9:15 am

    Implementing a custom QWidget by overloading the QWidget::paintEvent and using a painter is about the lowest level in Qt using the widget system.

    Here is a full working example using C++ I’ve put together for you, I don’t know PyQt but hopefully you can port this!

    widget.h

    #ifndef _WIDGET_H_
    #define _WIDGET_H_
    
    #include <QtGui>
    
    class CustomPaint : public QWidget
    {
        Q_OBJECT
        protected:
            virtual void paintEvent(QPaintEvent* event);
    };
    
    #endif
    

    widget.cpp

    #include "widget.h"
    
    void CustomPaint::paintEvent(QPaintEvent* ev)
    {
        QPainter painter(this);
        painter.setClipRect(ev->rect());
        painter.fillRect(ev->rect(), Qt::white);
    
        const int x = 10;
        const int y = 10;
        const int w = width() - 20;
        const int h = height() - 20;
    
        painter.setPen(QPen(QBrush(Qt::red), 0.0, Qt::DashLine));
        painter.drawRect(x, y, w, h);
    
        painter.setPen(QPen(QBrush(Qt::black), 0.0, Qt::SolidLine));
        painter.drawText(x, y, w, h,
            Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap,
            tr("Hello World"));
    }
    

    test.cpp

    #include <QtGui>
    #include "widget.h"
    
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
    
        CustomPaint win;
        win.show();
    
        return app.exec();
    }
    

    test.pro

    QT=core gui
    HEADERS=widget.h
    SOURCES=test.cpp widget.cpp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This is similar, but not quite the same as this other question I've
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note This is not a REBOL-specific question. You can answer it in any language.
Note: I have a workaround to this problem, but I'd prefer to comma-separate the
gsub('$0\n','') isn't working I would prefer something similar. I want: (note the 10 and
Note that I am not asking which to choose (MVC or MVP), but rather
Note : The code in this question is part of deSleeper if you want
Note The question below was asked in 2008 about some code from 2003. As
I would prefer to have an empty line prior to the last return statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.