PDA

View Full Version : How to rotate the control?



tszzp
19th November 2009, 03:04
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.

wysota
19th November 2009, 09:39
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()

tszzp
20th November 2009, 08:30
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.

wysota
20th November 2009, 08:36
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.

tszzp
23rd November 2009, 02:39
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.

wysota
23rd November 2009, 09:01
By calling QGraphicsItem::rotate() on some of them and not calling it on others.

tszzp
24th November 2009, 03:05
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.

wysota
24th November 2009, 08:21
Did you try at least going throught the examples in the documentation?

QGraphicsScene::addWidget()

tszzp
25th November 2009, 03:05
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.

wysota
25th November 2009, 09:05
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.