Results 1 to 10 of 10

Thread: How to rotate the control?

  1. #1
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to rotate the control?

    Now I'm port a WPF(Windows Presentation Foundation) program to Qt because the WPF program's performance is bad. during the port process, I find WPF support many feature directly(in a simple mode), but Qt haven't, So I have some questions. they are as follow:

    1) How to rotate the control(derived from QWidget)? and How to rotate it by the specified point(such as its center)? WPF is very easy to do it. I know QPainter has a rotate() function, using the method, I need subclass the rotate target from the corresponding control class(such as QPushButton). Can you tell me if there are a better method to implement the feature?

    2) WPF alignment have four flags: Left, Center, Right and Stretch. I want to know how to implement the the stretch alignment in the Qt?

    3) WPF stretch flags have: None, Uniform, UniformToFill, Fill. such as stretch a image in a control as follow:
    The Stretch property controls how an image is stretched to fill its container. The Stretch property accepts the following values, defined by the Stretch enumeration:

    None: The image is not stretched to fill the output area. If the image is larger than the output area, the image is drawn to the output area, clipping what does not fit.

    Fill: The image is scaled to fit the output area. Because the image height and width are scaled independently, the original aspect ratio of the image might not be preserved. That is, the image might be warped in order to completely fill the output container.

    Uniform: The image is scaled so that it fits completely within the output area. The image's aspect ratio is preserved.

    UniformToFill: The image is scaled so that it completely fills the output area while preserving the image's original aspect ratio.
    You can view the effect in the http://msdn.microsoft.com/en-us/library/ms748873.aspx.
    Can you tell me how to implement the stretch feature in Qt?

    4) WPF support some Layout, such as Grid, it is also a control. so it can set the its width and height. I know Qt also have the layout QGridLayout, but I find it isn't derived from QWidget. Can you tell me if I can set the QGridLayout's width or height? If can, which function can set it? thanks.

  2. #2
    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: How to rotate the control?

    Quote Originally Posted by tszzp View Post
    1) How to rotate the control(derived from QWidget)? and How to rotate it by the specified point(such as its center)? WPF is very easy to do it. I know QPainter has a rotate() function, using the method, I need subclass the rotate target from the corresponding control class(such as QPushButton). Can you tell me if there are a better method to implement the feature?
    The easiest way is to just put it into QGraphicsView (or QGraphicsScene actually) and rotate it like any other item.

    2) WPF alignment have four flags: Left, Center, Right and Stretch. I want to know how to implement the the stretch alignment in the Qt?
    We use layouts that distributes space to its children based on stretches and size policies. It's a much more powerful mechanism than just four flags.

    4) WPF support some Layout, such as Grid, it is also a control. so it can set the its width and height. I know Qt also have the layout QGridLayout, but I find it isn't derived from QWidget. Can you tell me if I can set the QGridLayout's width or height? If can, which function can set it? thanks.
    QWidget::setLayout()
    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.


  3. #3
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: How to rotate the control?

    Quote Originally Posted by wysota View Post
    The easiest way is to just put it into QGraphicsView (or QGraphicsScene actually) and rotate it like any other item.

    QWidget::setLayout()
    Can you explain it in detail mode? for example, when I rotate the button, I know I can put
    the button in the QGraphicsView, then rotate the total view. but maybe in my program, there are some controls, some of them need rotate, but others don't need rotate. How to do it? when I rotate a button, if I need override a class from QGraphicsItem to draw the QPushButton. if so,how to draw the QPushButton in the the derived class. If it is wrong, can you give me a simple sample or simple code snippet. thanks.

  4. #4
    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: How to rotate the control?

    In your situation I would put all your widgets into Graphics View and use that as a top-level widget (or central widget of the main window). You will have to make sure that when it is resized, its scene size and containing items get adjusted.
    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.


  5. #5
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: How to rotate the control?

    put all your widgets into Graphics View? how to rotate some controls and doesn't rotate the other control in a same graphics view? thanks.

  6. #6
    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: How to rotate the control?

    By calling QGraphicsItem::rotate() on some of them and not calling it on others.
    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.


  7. #7
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to rotate the control?

    I know QGraphicsItem have a rotate() function, if do so, so I need override a class from QGraphicsItem to draw the QPushButton(such as rotate the button). if so,how to draw the QPushButton in the the derived class. If it is wrong, can you give me a simple sample or simple code snippet. thanks.

  8. #8
    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: How to rotate the control?

    Did you try at least going throught the examples in the documentation?

    QGraphicsScene::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.


  9. #9
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to rotate the control?

    I know the function QGraphicsScene::addWidget() , but QGraphicsScene have the rotate function, so if use the addWidget function add the control into QGraphicsScene, how to let it rotate? subclass the control, paint it with the rotate angle?

    You give me a good suggestion. I will read document when I'm free. Now I have an urgent thing to do. thank you for your help.

  10. #10
    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: How to rotate the control?

    Quote Originally Posted by tszzp View Post
    I know the function QGraphicsScene::addWidget() , but QGraphicsScene have the rotate function, so if use the addWidget function add the control into QGraphicsScene, how to let it rotate? subclass the control, paint it with the rotate angle?
    What does QGraphicsScene::addWidget() return? What classes do this return object inherit? What API do they have?

    Now I have an urgent thing to do. thank you for your help.
    Writing such things here is a good first step to not being helped... So that you know... We all have urgent things to do yet we come here and try to help you solve your problem. So at least be polite.
    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.


  11. The following user says thank you to wysota for this useful post:

    tszzp (25th November 2009)

Similar Threads

  1. Replies: 3
    Last Post: 7th October 2015, 19:43
  2. Replies: 6
    Last Post: 11th November 2009, 10:42
  3. rotate operation and cpu usage
    By ersin.ozkan in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2008, 06:42
  4. QTextEdit control
    By vijay anandh in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2006, 13:14
  5. Replies: 6
    Last Post: 3rd February 2006, 09:48

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.