How to create a settings Menu?
-
wrote on 28 Mar 2013, 21:02 last edited by
Hi, I need to add menu (Blackberry style), but I can't. My proyect use QWidget, UI.
I tested this code:
@
...
// Create the application menu
Menu *menu = new Menu;// Create the actions and add them to the menu
ActionItem *actionOne = ActionItem::create()
.title("Action 1");
ActionItem *actionTwo = ActionItem::create()
.title("Action 2");
menu->addAction(actionOne);
menu->addAction(actionTwo);// Set the menu of the application
Application::instance()->setMenu(menu);
...
@
(from http://developer.blackberry.com/cascades/documentation/ui/navigation/menus.html)--
Can I use Cascades objects (ActionItem, Menu) in Qt? If I use qt objects (QMenubar, QAction), the menu is always visible.edit: code belongs between @ tags; Andre
-
wrote on 29 Mar 2013, 00:46 last edited by
I ran into this myself. I didn't look into the Cascades version as I was targeting a playbook (Cascades doesn't exist on this platform).
I was able to replicate this without too much effort using a QToolBar subclass to show or hide based on key events:
@
void TMainWindow::keyPressEvent(
QKeyEvent *event)
{
switch(event->key())
{
case Qt::Key_Menu:
case Qt::Key_Meta:
case Qt::Key_Super_L:
case Qt::Key_Super_R:
d_AnimatedToolBar->Toggle_Visibiliy();
event->accept();
return;
}
QMainWindow::keyPressEvent(event);
}
@For the nice roll out effect:
@
void TAnimatedToolBar::Toggle_Visibiliy(void)
{
QRect rect(this->rect());QPropertyAnimation *toolbar_animation = new QPropertyAnimation(this, "geometry");
if(rect.height() < (d_visible_height/2))
{
toolbar_animation->setDuration(250);
toolbar_animation->setStartValue(rect);rect.setHeight(d_visible_height);
toolbar_animation->setEndValue(rect);connect(toolbar_animation,SIGNAL(valueChanged(const QVariant&)),this,SLOT(Size_Changed(const QVariant&)));
toolbar_animation->start();
}
else
{
toolbar_animation->setDuration(250);
toolbar_animation->setStartValue(rect);rect.setHeight(0);
toolbar_animation->setEndValue(rect);connect(toolbar_animation,SIGNAL(valueChanged(const QVariant&)),this,SLOT(Size_Changed(const QVariant&)));
toolbar_animation->start();
}
}void TAnimatedToolBar::Size_Changed(
const QVariant &value)
{
QRect rect;rect = value.toRect();
this->setMinimumSize(0,rect.height());
this->setMaximumSize(16777215,rect.height());
}
@And for the appearance (a dark gradient background) I used this:
@
void TAnimatedToolBar::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect rect(event->rect());
QLinearGradient vertical_gradient(rect.topLeft(), rect.bottomLeft());vertical_gradient.setColorAt(0, QColor(64,64,64,255)); vertical_gradient.setColorAt(1, QColor(0,0,0,255)); painter.fillRect(rect, vertical_gradient);
}
@It works and looks very much like the native version. Depending on how the widget is added to the main window it can either go over or push existing widgets to make room.
If you want an actual menu you should be able to add it to the widget but I personally would try to use symbols (icons) instead. The menu would be difficult to use on a touch screen. I can't think of an app that successfully uses a menu (a real menu).
-
wrote on 29 Mar 2013, 13:29 last edited by
Hi Rondog, thanks for your help, your source code is very interesting, I will try to implement it.
My project uses MainWidget, the original version of the project (Symbian) used MainWindow.
I tell you that a week ago I heard of Qt for BlackBerry, I want to port my app. The most important functions of the app are:- Send and receive SMS automatically (Not ported)
- Making and accepting requests http automatically (ported)
- Sqlite data base management (ported)
The quality of the graphical interface is secondary.
Apparently Qt Creator has limitations, I will try to implement the most important functions (Send and receive SMS automatically). If I solve the problem, I will continue with the GUI, but if I have problems I'll have to start using
BlackBerry Native SDK. Thank you very much.
3/3