Results 1 to 15 of 15

Thread: Rotate QGraphicsProxyWidget in QGraphicsView

  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Rotate QGraphicsProxyWidget in QGraphicsView

    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.
    Qt Code:
    1. QGraphicsView view(&scene);
    2.  
    3. view.setRenderHint(QPainter::Antialiasing);
    4. view.setDragMode(QGraphicsView::ScrollHandDrag);
    5.  
    6. QPushButton *btn = new QPushButton("My Button");
    7. QGraphicsProxyWidget *pw = scene.addWidget(wi);
    8. pw->setPos(100, 100);
    9. pw->setRotation(-20);
    To copy to clipboard, switch view to plain text mode 

    Any pointer would be of great help.
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Use QPropertyAnimation
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Shouldn't you be using "btn" instead of "wi" in the call to scene.addWidget()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Sorry I forgot to mention about the following. The wi is defined as follows
    Qt Code:
    1. QWidget *wi = new QWidget;
    2. lay->addWidget(new QPushButton("Hello"));
    3. lay->addStretch();
    4. wi->setLayout(lay);
    5. scene.setSceneRect(0, 0, 500, 500);
    6.  
    7. QGraphicsView view(&scene);
    8.  
    9. view.setRenderHint(QPainter::Antialiasing);
    10. view.setDragMode(QGraphicsView::ScrollHandDrag);
    11.  
    12. QGraphicsProxyWidget *pw = scene.addWidget(wi);
    13. pw->setPos(100, 100);
    14. pw->setRotation(-20);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    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?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Yes the code is present in the main.

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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    What do you mean by "the view of the button"? How about providing an image mockup of "what is" and "what should be"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Attached what's happening ans what is required
    Attached Images Attached Images

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    And what about a complete code you used to obtain it? When I run my code, I get the required output
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    I just made my complete working code:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication a(argc, argv);
    7. QGraphicsScene scene(-200,-200,400,400);
    8. gv.setScene(&scene);
    9. gv.setRenderHint(QPainter::Antialiasing);
    10. gv.setDragMode(QGraphicsView::ScrollHandDrag);
    11.  
    12. QWidget wi;
    13. QPushButton btn("My Button", &wi);
    14. lo.addWidget(&btn);
    15. wi.setLayout(&lo);
    16. QGraphicsProxyWidget *pw = scene.addWidget(&wi);
    17. pw->setPos(0, 0);
    18. pw->setRotation(-20);
    19. gv.show();
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    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)
    Attached Images Attached Images
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    What if you get rid of the "wi" widget and the layout? What if you call rotate() instead of setRotation()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication a(argc, argv);
    7. QGraphicsScene scene(-200,-200,400,400);
    8. gv.setScene(&scene);
    9. gv.setRenderHint(QPainter::Antialiasing);
    10. gv.setDragMode(QGraphicsView::ScrollHandDrag);
    11.  
    12. QPushButton btn("My Button");
    13. QGraphicsProxyWidget *pw = scene.addWidget(&btn);
    14. pw->setPos(0, 0);
    15. pw->rotate(-20);
    16. gv.show();
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    gives:
    screen2.jpg
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  13. #13
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    Is there a solution to this problem ?

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    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
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsProxyWidget in QGraphicsView

    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. QGraphicsItem or QGraphicsProxyWidget?
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 30th August 2009, 23:13
  2. performance of QWebKit() in QGraphicsProxyWidget
    By wagmare in forum Qt Programming
    Replies: 11
    Last Post: 8th December 2008, 10:26
  3. QGraphicsProxyWidget
    By QbelcorT in forum Qt Programming
    Replies: 0
    Last Post: 29th November 2008, 08:21
  4. window icon in QGraphicsProxyWidget
    By Maike.F in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2008, 13:50
  5. problem with QGraphicsProxyWidget
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2008, 22:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.