Re: Rotate QTextEdit Widget
If you have a pointer to your labels, and you have overriden their paintEvent() that should be enough, if you use trasformation (totate) on in your paintEvent() of your labels.
Quote:
This runs without error, but does not have the desired effect.
What is the effect you did get - and please post code for it.
Another thing your might want to consider, is using a ready made such QLabel that allow rotation.
You can find it here:
libQxt
Re: Rotate QTextEdit Widget
Thank you for taking the time to reply.
I have been working out a trivial example to demonstrate what I am trying to accomplish. Here is what I have:
The project contains a standard QMainWindow with only a centralWidget.
main.cpp
Code:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "myqpushbutton.h"
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
MyQPushButton *pb;
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
pb = new MyQPushButton(ui->centralWidget);
pb->show();
}
MainWindow::~MainWindow()
{
delete pb;
delete ui;
}
myqpushbutton.h
Code:
#ifndef MYQPUSHBUTTON_H
#define MYQPUSHBUTTON_H
#include <QPushButton>
{
Q_OBJECT
public:
explicit MyQPushButton
(QWidget *parent
= 0);
private:
signals:
public slots:
};
#endif // MYQPUSHBUTTON_H
myqpushbutton.cpp
Code:
#include "myqpushbutton.h"
#include <QPaintEvent>
#include <QPainter>
MyQPushButton
::MyQPushButton(QWidget *parent
) :{
}
{
painter.rotate(45);
}
With this configuration, the button is painted on the form, but it is painted in a normal horizontal position. I presume this is due to the fact that I am calling the paintEvent of the inherited class QPushButton. If I remove the line
Code:
QPushButton::paintEvent(e);
however, nothing is drawn. I can call painter.drawText() and the text will be printed at the desired angle.
I have looked through libQxt, and while an excellent project, they only provide rotation at 90, 180 and 270 degrees. I am attempting to attain an arbitrary angle.
Once again, thank you for your time, and I would appreciate any further input.
Re: Rotate QTextEdit Widget
Quote:
I have looked through libQxt, and while an excellent project, they only provide rotation at 90, 180 and 270 degrees.
If all you want is to rotate text in a QLabel, all you have to do is resize the label to the bounding rect of the result string, rotate the painter, and do drawText() as you did.
But if you want to have a complex widget such as a QPushButton drawn as it is usually drawn just rotated, this makes it more complicated.
You will have to calculate the widgets bounding rect for the given angel, resize is, and then run the drawing code (which you basically have to copy from the original widget).
Another approach might be to use QGraphicsViewer and proxy widgets - then rotating is trivial.