PDA

View Full Version : Rotate QGraphicsProxyWidget in QGraphicsView



volcano
11th January 2010, 05:23
Hi,

I have a QPushButton on a QGraphicsProxyWidget. However when I rotate the proxy widget, the widget rotates but the rotation of the button is cannot be seen. Is it possible to rotate the QPushButton to appear rotated say at an angle of -20.


QGraphicsView view(&scene);

view.setRenderHint(QPainter::Antialiasing);
view.setDragMode(QGraphicsView::ScrollHandDrag);

QPushButton *btn = new QPushButton("My Button");
QGraphicsProxyWidget *pw = scene.addWidget(wi);
pw->setPos(100, 100);
pw->setRotation(-20);


Any pointer would be of great help.
Thanks

MarkoSan
11th January 2010, 10:14
Use QPropertyAnimation

wysota
11th January 2010, 11:02
Shouldn't you be using "btn" instead of "wi" in the call to scene.addWidget()?

volcano
11th January 2010, 12:32
Sorry I forgot to mention about the following. The wi is defined as follows


QWidget *wi = new QWidget;
QVBoxLayout *lay = new QVBoxLayout;
lay->addWidget(new QPushButton("Hello"));
lay->addStretch();
wi->setLayout(lay);
QGraphicsScene scene;
scene.setSceneRect(0, 0, 500, 500);

QGraphicsView view(&scene);

view.setRenderHint(QPainter::Antialiasing);
view.setDragMode(QGraphicsView::ScrollHandDrag);

QGraphicsProxyWidget *pw = scene.addWidget(wi);
pw->setPos(100, 100);
pw->setRotation(-20);

faldzip
11th January 2010, 14:03
Can you provide compilable example, because it is hard to understand what yo want to do. Once you are making a button and NOT adding it to any scene and you are rotating another widget which has nothing common with this button, so, as it can be expected, the button is not rotated... In you last post you have widget with button but it looks strange that you create scene and graphics view on a stack instead of heap, so where do you have this code? in main() function?

volcano
12th January 2010, 04:50
Yes the code is present in the main.

The problem faced is that the button rotates but the view of the button doesn't.

wysota
12th January 2010, 09:44
What do you mean by "the view of the button"? How about providing an image mockup of "what is" and "what should be"?

volcano
12th January 2010, 11:49
Attached what's happening ans what is required

wysota
12th January 2010, 12:20
And what about a complete code you used to obtain it? When I run my code, I get the required output :)

faldzip
12th January 2010, 12:31
I just made my complete working code:


#include <QtCore>
#include <QtGui>

int main(int argc, char **argv)
{
QApplication a(argc, argv);
QGraphicsView gv;
QGraphicsScene scene(-200,-200,400,400);
gv.setScene(&scene);
gv.setRenderHint(QPainter::Antialiasing);
gv.setDragMode(QGraphicsView::ScrollHandDrag);

QWidget wi;
QVBoxLayout lo;
QPushButton btn("My Button", &wi);
lo.addWidget(&btn);
wi.setLayout(&lo);
QGraphicsProxyWidget *pw = scene.addWidget(&wi);
pw->setPos(0, 0);
pw->setRotation(-20);
gv.show();
return a.exec();
}

And what I get is on the screenshot. Am I missing something in my code?
EDIT:
The button is only displayed correctly when the Aero highlighting animation takes place on hover (when finished it is displayed wrong again)

wysota
12th January 2010, 12:38
What if you get rid of the "wi" widget and the layout? What if you call rotate() instead of setRotation()?

faldzip
12th January 2010, 12:46
#include <QtCore>
#include <QtGui>

int main(int argc, char **argv)
{
QApplication a(argc, argv);
QGraphicsView gv;
QGraphicsScene scene(-200,-200,400,400);
gv.setScene(&scene);
gv.setRenderHint(QPainter::Antialiasing);
gv.setDragMode(QGraphicsView::ScrollHandDrag);

QPushButton btn("My Button");
QGraphicsProxyWidget *pw = scene.addWidget(&btn);
pw->setPos(0, 0);
pw->rotate(-20);
gv.show();
return a.exec();
}

gives:
4113

volcano
13th January 2010, 07:07
Is there a solution to this problem ?

wysota
13th January 2010, 12:21
The solution is to use a widget style different than the native WindowsXP/Vista style. You may also browse the bug tracker to see if this bug was reported and fixed between 4.6.0 and 4.6.1. If so, you can download a patch and apply it to your 4.6.0 sources and rebuild the style. You may also downgrade to Qt 4.5.3

faldzip
13th January 2010, 14:58
http://bugreports.qt.nokia.com/browse/QTBUG-5939