QPainter::drawText() draws distorted text in some combinations of font size and font stretch factor
-
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 mutexI 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();
}
@@
// MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
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 );
}
@ -
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
-
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.
-
Don't forget to also post your new bug report here so other may follow
-
I just created a bug report.
"QTBUG-32991":https://bugreports.qt-project.org/browse/QTBUG-32991