[solved] Rotating a whole UI



  • Hi

    I am working on a simple interface with pushbuttons and labels, and after making it, it appears that it should be rotated at right angle to suit the final need.

    Now I would like to avoid doing it for every single part of the interface. I tried this, based on some research in documentation:

    @void MyInterface::paintEvent(QPaintEvent*)
    {
    QPainter painter(this);
    painter.rotate(-90);
    }@

    Yet it did not work (the interface was not rotated at all). So after some more research in documentation and forums, I came up with this:

    @void MyInterface::paintEvent(QPaintEvent*)
    {
    QPainter painter(this);
    QStyleOptionComplex option;
    QSize size;

    option.initFrom(this);
    size = option.rect.size();
    size.transpose();
    option.rect.setSize(size);
    painter.rotate(-90);
    style()->drawComplexControl(QStyle::CC_CustomBase, &option, &painter, this);
    

    }@

    But it is still not working (same result as for the first attempt).

    Does anyone know why it is not working, and possibly an actual way to make that rotation ?
    Thank you in advance.

    I am working on Windows 7 (64-bit), with Qt 4.8.5 and compiling with Visual Studio 2008. The target OS is Windows XP.


  • Moderators

    what widgets are you trying to rotate? your whole mainwindow?

    Also note that just rotating the visible part of your application (paintEvent) will break your application, since all input events wont work as expected anymore.

    i would go for a QGraphicsView and and insert QGraphicsProxyWidgets in there and rotate the view itself. Then the input events are still working.

    But please tell us more about your use case. Because rotating the whole GUI seems a bit strange to me ;)



  • Thank you for your reply.

    I am trying to rotate the whole main window yes. It is designed to fit into a specific embedded application, and the orientation would need to be rotated at a right angle as I said.

    I am giving a try to QGraphicsProxyWidget. I will tell you the outcome.



  • Yeah ! Your solution is working. Here is the snippet:

    @QGraphicsScene scene;
    QGraphicsProxyWidget *proxy = scene.addWidget(&MyInterfaceInstance);
    QGraphicsView view(&scene);
    view.rotate(-90);
    view.show();@

    Just a few questions:

    • The application now crashes when I close it. Do you have any idea of what could be the reason ?
    • Is it possible to give initially to the window the proper size ? I tried setSceneRect, but the result is ... strange. Maybe am I not using it properly (especially the x and y parameters).
    • Is it possible to remove the window frame around the interface ? It would be better looking without it (as it was without the GraphicView wrapping).

    Thanks again.


  • Moderators

    [quote author="alvqt" date="1375444716"]

    • The application now crashes when I close it. Do you have any idea of what could be the reason ?
      [/quote]
      No... my glass ball is broken ;)
      Show the stack trace of the crash please.

    [quote author="alvqt" date="1375444716"]

    • Is it possible to give initially to the window the proper size ? I tried setSceneRect, but the result is ... strange. Maybe am I not using it properly (especially the x and y parameters).
      [/quote]
      Well this depends on the orientation.
      But QGraphicsView::sceneRect() should be the correct way.

    [quote author="alvqt" date="1375444716"]

    • Is it possible to remove the window frame around the interface ? It would be better looking without it (as it was without the GraphicView wrapping).
      [/quote]
      Since the graphicsview becomes your new top-level widget - and i assume your intial mainwindow still is also - you can set the the parent widget of your old mainwindow widget to the graphics view. This should remove the top-level frame...


  • Sounds like something to solve in your display manager instead of in Qt. I would recommend against using a QGraphicsView inbetween. QGraphicsProxyWidget has many issues, and is generally considered a failed experiment.



  • To raven-worx:
    I have no tool at hand to get a stack trace, but I got "this":http://postimg.org/image/acsyr8lqf/ in debug mode in Qt Creator.

    And concerning the window frame, setting the graphics view as parent of the interface did not remove it. It even added some sort of padding into the window, which is of course not what I am looking for.

    To andre:
    Unhappily I can not use the display manager of the target PC. It seems to have some graphical problem, which makes screen rotation not functional.
    So even though QGraphicsProxyWidget (am I actually using it ?... the subsequent commands do not involve the created instance, so I just removed the assignment) might have some problems, I will stick to it, unless there is a better solution (?)


  • Moderators

    regarding the frame:
    @
    w->setWindowFlags( Qt::Widget | Qt::FramelessWindowHint );
    @
    i'm not sure at the moment, but you can also try to set the parent and hide it before you add it to the graphicsview. Not sure if this works though.

    regarding the crash:
    Seems like an assertion in the msvc runtime. Don't know if this is caused by your code, maybe.
    Hard to tell without stack-trace (e.g. from QtCreator or Visual Studio)



  • Yep windowFlags does the trick !
    Thanks again :)

    I am not sure how to get a stack trace in Qt Creator yet. I will work on that and get back to u.



  • I might not be able to investigate on that properly for now, since I need to work on something else.
    But the main problem is solved.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.