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
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "myqpushbutton.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
MyQPushButton *pb;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#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;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
pb = new MyQPushButton(ui->centralWidget);
pb->show();
}
MainWindow::~MainWindow()
{
delete pb;
delete ui;
}
To copy to clipboard, switch view to plain text mode
myqpushbutton.h
#ifndef MYQPUSHBUTTON_H
#define MYQPUSHBUTTON_H
#include <QPushButton>
{
Q_OBJECT
public:
explicit MyQPushButton
(QWidget *parent
= 0);
private:
signals:
public slots:
};
#endif // MYQPUSHBUTTON_H
#ifndef MYQPUSHBUTTON_H
#define MYQPUSHBUTTON_H
#include <QPushButton>
class MyQPushButton : public QPushButton
{
Q_OBJECT
public:
explicit MyQPushButton(QWidget *parent = 0);
private:
void paintEvent(QPaintEvent *e);
signals:
public slots:
};
#endif // MYQPUSHBUTTON_H
To copy to clipboard, switch view to plain text mode
myqpushbutton.cpp
#include "myqpushbutton.h"
#include <QPaintEvent>
#include <QPainter>
MyQPushButton
::MyQPushButton(QWidget *parent
) :{
}
{
painter.rotate(45);
}
#include "myqpushbutton.h"
#include <QPaintEvent>
#include <QPainter>
MyQPushButton::MyQPushButton(QWidget *parent) :
QPushButton(parent)
{
}
void MyQPushButton::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
painter.rotate(45);
QPushButton::paintEvent(e);
}
To copy to clipboard, switch view to plain text mode
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
QPushButton::paintEvent(e);
QPushButton::paintEvent(e);
To copy to clipboard, switch view to plain text mode
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.
Bookmarks