Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-32991

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.0.2, 5.1.0
    • Fix Version/s: None
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Environment:
      Ubuntu 12.04 32 Bit, GNOME Classic 3.4.1
      Fedora 19, 32 Bit, GNOME 3.8

      Description

      If a QFont with stretch is used, QPainter::drawText() renders the Text realy strange. This behavior only occurs on Linux (tested with Ubuntu 12.04 and Fedora 19). There are an example of the distortion in the following image.

      By way of comparison, the second image shows the same output on a Windows 7x64 System, which shows the Text as might be desired. The same font is used like on Linux.

      I have tested this behavior with Qt 5.1 and 5.0.2. I also used other fonts. That makes no difference. I haven't tested on older versions of Qt.

      Perhaps there is a deadlock in the drawText method. If the text is rendered Strange there is the following warning on stderr:
      [warning] (thread/qmutex.cpp:194) – QMutex: destroying locked mutex

      The following code generates the output shown in the images. It is also attached to this issue.

      main.cpp
      #include "MainWindow.h"
      #include <QApplication>
       
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
         
          return a.exec();
      }
      
      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();
      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 );
      }
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            esabraha Eskil Abrahamsen Blomfeldt
            Reporter:
            ckagerer Christian Kagerer
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes