How to place an icon at the center of the screen on Qt Symbian?
Question
How can I place an icon at the center of screen on Qt Symbian? At the moment I'm using the following:
p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0));
But what I need is for the icon to be automatically set to the center of the screen.
Solution
Use QDesktopWidget to get screen geometry (don't be scared by its name ^^).
//Sample code
QRect screen = qApp->desktop()->screenGeometry();
int iconSize = 64;
p3->setGeometry(QRectF(screen.width()/2 - iconSize/2, screen.height()/2 - iconSize/2, iconSize, iconSize));
OTHER TIPS
Your best bet is to use layouts instead of hardcoding positions. Using a layout allows you to use Qt.Align to center QWidgets .
If you don't want to use layouts. You can do something like
int xpos = parent->width()/2 - p3->width()/2
int ypos = parent->height()/2 - p3->height()/2
p3->setGeometry(QRectF(xpos,ypos, 64.0, 64.0));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow