Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Rotating a whole UI
QtWS25 Last Chance

[solved] Rotating a whole UI

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 7.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alvqt
    wrote on 2 Aug 2013, 11:14 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 2 Aug 2013, 11:27 last edited by
      #2

      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 ;)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alvqt
        wrote on 2 Aug 2013, 11:35 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alvqt
          wrote on 2 Aug 2013, 11:58 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 2 Aug 2013, 12:05 last edited by
            #5

            [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...

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 2 Aug 2013, 12:10 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alvqt
                wrote on 2 Aug 2013, 12:55 last edited by
                #7

                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 (?)

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 2 Aug 2013, 13:48 last edited by
                  #8

                  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)

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alvqt
                    wrote on 2 Aug 2013, 14:14 last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alvqt
                      wrote on 5 Aug 2013, 07:06 last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0

                      7/10

                      2 Aug 2013, 12:55

                      • Login

                      • Login or register to search.
                      7 out of 10
                      • First post
                        7/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved