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. QPainter::drawText() draws distorted text in some combinations of font size and font stretch factor
Forum Updated to NodeBB v4.3 + New Features

QPainter::drawText() draws distorted text in some combinations of font size and font stretch factor

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.9k 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.
  • C Offline
    C Offline
    ckagerer
    wrote on last edited by
    #1

    Hey,

    I have a problem with QPainters drawText() method. Which I think is a Bug in Qt.

    If i run the following minimal demonstration application on my Ubuntu 12.04 the drawText() produces a deformed output how you can see on the following pictures.
    The Problem can also be reproduced on a Fedora 19 machine. If I run the same Application on Windows the output is like expected (same font is installed/used).

    The deformation only appears on some combinations (ranges?!?) of font-size and font-stretch-factor. In such cases the is alwas a warning in stderr when closing the programm, which says:
    [warning] (thread/qmutex.cpp:194) - QMutex: destroying locked mutex

    I could reproduce this behavieor with Qt 5.1 and 5.0.2 and with other fonts.

    Is this a Bug in Qt and has anybody a workaround for this Problem?

    Screenshot Ubuntu 12.04 32Bit (Gnome Classic)
    !http://up.picr.de/15492086jj.png(Ubuntu 12.04)!

    Screenshot Windows 7 64Bit
    !http://up.picr.de/15492087kf.png(Windows 7 64Bit)!

    @
    // Main.cpp
    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }
    @

    @
    // MainWindow.h
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QString GetFont(&#41;;
    

    protected:
    void paintEvent(QPaintEvent *ap_event);

    private:
    Ui::MainWindow *ui;
    QFont font;
    };

    #endif // MAINWINDOW_H
    @

    @
    // MainWindow.cpp
    #include "MainWindow.h"
    #include "ui_MainWindow.h"

    #include <QPainter>

    MainWindow::MainWindow( QWidget *parent ) :
    QMainWindow( parent ),
    ui( new Ui::MainWindow ) {
    ui->setupUi( this );
    }

    MainWindow::~MainWindow() {
    delete ui;
    }

    void MainWindow::paintEvent( QPaintEvent */event/ ) {
    QString str( "Hello World" );
    QPoint pos( 10, 10 );

    QFont font( "Ubuntu Mono" );
    font.setPointSize( 40 );
    font.setStretch( 200 );
    font.setUnderline( true );
    font.setOverline( true );

    QFontMetrics fm( font );
    QRect boundingRect( pos, fm.size( 0, str ) );

    QPainter painter( this );
    painter.setPen( Qt::black );
    painter.fillRect( boundingRect, Qt::lightGray );
    painter.setFont( font );

    // probleme here
    // Warning: QMutex: destroying locked mutex
    painter.drawText( boundingRect, Qt::AlignCenter, str );
    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I indeed sounds like a bug, did you check the "bug report system":http://bugreports.qt-project.org/issues/ ?

      If nothing has been reported yet you may consider creating a new bug report

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckagerer
        wrote on last edited by
        #3

        Hey,

        Thank you for your help.

        I've checked the bug report system already. I couldn't find any Bug which distorted the text the same way like in may case.

        The Bug which comes close mine best is QTBUG-13682. But with an other form of distortion.

        Therefore I will create a new bug report during the day.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Don't forget to also post your new bug report here so other may follow

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ckagerer
            wrote on last edited by
            #5

            I just created a bug report.

            "QTBUG-32991":https://bugreports.qt-project.org/browse/QTBUG-32991

            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