Search TekSocial
Stay Connected

Enter your email address:

(We respect your privacy!)

Or subscribe with your favorite RSS Reader

  

« The countdown to WWDC | Main | HyperMac 32 Hour Battery Review »
2:09PM

Rotating Qt Apps in (literally) 6 Lines of Code

Recently, I've been striving to make the Codename Divingboard applications rotate from landscape to portrait. This would be handy if your computer's onboard display does not support rotation, allowing you to still use your applications in a portrait layout.

Here's a sample screenshot of the web browser for Codename Divingboard (currently called "WebView" internall):

- Please note, the UI choices in this sample screenshot are not final. There are no images or icons added to this version yet, because I haven't had the time to do proper graphics design. However, if you have any layout suggestions, feel free to suggest them! -

This is the application running at its native layout. But what if we wanted it turned, say, 70 degrees?

Isn't that neat? Unfortunately, due to obvious limitations of the windowkits in modern operating systems, we can't rotate the "traffic" controls or window header. However, everything else rotates!

Here's how to add this to your Qt application:

1 - Open the main class definition file (.cpp)

2 - Add the following lines (in the constructor):

QGraphicsScene *scene = new QGraphicsScene();

QGraphicsView *view = new QGraphicsView(parent);

QGraphicsProxyWidget *proxy = scene->addWidget(this);

view->setScene(scene);

view->show();

view->rotate(70);

3 - This will add your UI to a QGraphicsScene, then display the QGraphicsView and rotate it.

This method will, unfortunately, not resize the layout if you have one defined, although I believe that there are functions within QGraphicsView that involve resizing elements based on the size of the main window.

Enjoy your new sideways applications!

For more updates on touch-enabled applications for your computer, as well as other development news, feel free to check out peterhajas.com, especially the blog and my twitter. For video updates, check out my YouTube page.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>