PDA

View Full Version : Twisted Letters in Vertical Axis Title



DrunkenUFOPilot
6th January 2011, 22:36
Qwt makes plots just fine on the monitor, but when asked to save to an image file using QwtPlot;;print(QPainter, ...) it fails to rotate the letters in the vertical scale's text.

As a hack to investigate, I added code to write the labels for the tic marks at an angle. Note that for these too, the on-screen rendering is fine but the print( ) version shows the letters untransformed. The screen rendering doesn't use print(). How it does work, I'm not entirely sure, just that it has a completely different path of execution.

The app I'm working on is very complex, with code in hundreds of classes, messy multiple inheritance, too few comments and poor naming non-conventions. Somehow QwtPlot;;print() has a different idea about font angles than whatever normally does the drawing. Even after several months working on this source code, I've never found anyplace where angles are mentioned regarding fonts for vertical (or horizontal) axes.

Could this be a bug in QwtPlot;;print( )? Are there any properties of QwtPlot or some object connected to it that needs to be given some parameter? Advice for nailing this bug?

(note: by ;; I eally mean two colons. This online editor wants to convert double colons to a smileyface. Don't know how to disable this.)

I'm using Qt4.3.4, qwt 5.1.1 on a Red Hat 5 machine running KDE 3.5.4. Several users with different systems see the same bad vertical scale rendering.

As drawn on screen, coming out fine:
http://www.aoc.nrao.edu/~dwilson/temp/twistybug_onscreen.png

As drawn to a .png file using print() (and also, why is it gray? Our app does not say anywhere to change the color):
http://www.aoc.nrao.edu/~dwilson/temp/twistybug_exported1.png

Uwe
11th January 2011, 06:46
Post some ( compilable ) code and I will run it on my system, to check what is going on.

Uwe

DrunkenUFOPilot
11th January 2011, 23:48
I'd have to write a small demo app from scratch, and somehow hope to find the same problem. Whittling down the real app would be impossible - hundreds of classes depending on each others' internals, macaroni code etc. A small demo may take a few days.

DrunkenUFOPilot
19th January 2011, 18:04
Here's a short demo using qwt that writes a .png image. On screen, the vertical axis is okay, but the .png image shows the letters failed to rotate 90 deg.



/* ------ myplot.hpp ------ */
#ifndef myplot_hpp
#define myplot_hpp

#include <qwt/qwt.h>
#include <qwt/qwt_plot.h>

class MyPlot : public QwtPlot
{
Q_OBJECT

public:

MyPlot();

void setup_details_1();
};


#endif




/* ------ myplot.cpp ------ */

#include "myplot.hpp"

MyPlot::MyPlot()
: QwtPlot()
{
}


void MyPlot::setup_details_1()
{
setTitle("Dizziness of Millisecond Pulsars");
setAxisTitle(QwtPlot::xBottom, "whizzyness");
setAxisTitle(QwtPlot::yLeft, "wooziness");
}




/* ------ qwtdemo2.hpp ------ */
#include <QtGui>
#include <QWidget>
#include "myplot.hpp"

class MyMainWindow : public QWidget
{
Q_OBJECT

public:
MyMainWindow(QWidget *parent=0);
~MyMainWindow();

void createcontents();

public slots:
void printmyplot();

private:
QPushButton *print_button;
QPushButton *quit_button;
public:
MyPlot* myplot;
};




/* ------ qwtdemo2.cpp ------ */
/*
simple demo using qwt
"print" button writes a .png file
see if vert scale text has unturned letters
*/

#include <QtGui>
#include <QWidget>
#include <stdio.h>
#include <unistd.h>

#include "myplot.hpp"
#include "qwtdemo2.hpp"

MyMainWindow::~MyMainWindow() {}

MyMainWindow::MyMainWindow(QWidget *parent)
: QWidget(parent), print_button(0), quit_button(0), myplot(0)
{
resize(500,500);
setWindowTitle("QWT Simple Demo #1");
}


void MyMainWindow::createcontents()
{
print_button = new QPushButton("print", this);
quit_button = new QPushButton("quit", this);
myplot = new MyPlot;

QHBoxLayout *bottomrow = new QHBoxLayout;
bottomrow->addWidget(print_button);
bottomrow->addWidget(quit_button);

QVBoxLayout *mainlayout = new QVBoxLayout;
mainlayout->addWidget(myplot);
mainlayout->addLayout(bottomrow); // use setLayout()?
setLayout(mainlayout);

connect(quit_button, SIGNAL(clicked()),
this, SLOT(close()));
connect(print_button, SIGNAL(clicked()),
this, SLOT(printmyplot()));
}


void MyMainWindow::printmyplot()
{
QImage image(500,500, QImage::Format_ARGB32);
QPainter painter(&image);
QRect rect(0,0, 500,500);
myplot->print(&painter, rect);
printf("aobut to save ");
image.save("000.png", "PNG", 1);
printf("return from ::printmyplot \n");
}


int main(int nargs, char** args)
{
QApplication app(nargs, args);

MyMainWindow *mainwindow = new MyMainWindow;
mainwindow->createcontents();
mainwindow->myplot->setup_details_1();
mainwindow->show();
return app.exec();
}




# .pro file to build qwtdemo2
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
INCLUDEPATH += $(QWT)/include
LIBS += -lqwt
HEADERS += myplot.hpp qwtdemo2.hpp
SOURCES += myplot.cpp qwtdemo2.cpp

Uwe
20th January 2011, 07:06
Here's a short demo using qwt that writes a .png image. On screen, the vertical axis is okay, but the .png image shows the letters failed to rotate 90 deg.

Not here ( Qt 4.7.1, Qwt 5.2 Linux/X11 ).

Your code does absolutely nothing special - so expect to find the source of the problem in your environment. The first candidate you should look for is your Qt version - Qt 4.3 is really too old. Another thing you should check is if it depends somehow on the font.

Qwt rotates the transformation matrix and then paints the title with a single QPainter::drawText. An effect where each letter is rotated individually can only be caused by a layer below.

Uwe

PS: Consider to use a scalable vector graphics format like PDF, what is much better format than using raster graphics.

DrunkenUFOPilot
20th January 2011, 21:42
PS: Consider to use a scalable vector graphics format like PDF,

I didn't think to mention it in the original question, but PDF (and .ps) files do look fine. For now, we can tell users to just make a PDF and then print that however they like.

Yeah, Qt 4.3.4 is old, and we have other issues unresolved that would go away with a newer Qt. Someday...

darenw
24th January 2012, 23:56
Follow-up for anyone who stumbles into this thread. Yes, the problem went away with an update of Qt4 version.

(Note: I am DrunkeUFOPilot with new shorter user name darenw)