maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Qt and Hildon menu (https://talk.maemo.org/showthread.php?t=34567)

hopbeat 2009-11-16 13:53

Qt and Hildon menu
 
Hello,

can someone tell me, how to get the menu, that appears from the top (for example when pressing clock in standby mode)?

QMenuBar is creating ad different style menu.
I'm using Qt 4.5 and Maemo 5.

attila77 2009-11-16 14:06

Re: Qt and Hildon menu
 
Depends on the actual build. A while ago you had to define a property o the QActions in it, nowadays it's automatic.

Hildon menus

Hildon menus are supported by Qt. qt-4.5.3-xxxx-maemo4 packages needs QActions in a "fremantle" menu. Packages with version > qt-4.5.3-xxxx-maemo4 hildonize the menu automaticall.

This and many other goodies found on

http://wiki.maemo.org/Qt4Hildon

Figa 2010-03-10 12:01

Re: Qt and Hildon menu
 
Please, can you give me some example?

krk969 2010-03-10 12:07

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Figa (Post 562401)
Please, can you give me some example?

Code:

action1 = new QAction(tr("&ACTION1"), this);
action2 = new QAction(tr("&ACTION2"), this);

menu = menuBar()->addMenu(tr("MENU TITLE"));
menu->addAction(action1);
menu->addAction(action2);

connect(action1, SIGNAL(triggered()), this , SLOT(doAction1()));
connect(action2, SIGNAL(triggered()), this , SLOT(doAction2()));


Figa 2010-03-10 16:40

Re: Qt and Hildon menu
 
THX I did it but I cant see any menu. What I do have to do?
Code:

QWidget *master = new QWidget();
                QAction *action1 = new QAction(tr("&ACTION1"), this);
                QAction *action2 = new QAction(tr("&ACTION2"), this);

                connect(action1, SIGNAL(triggered()), this , SLOT(doAction1()));
                connect(action2, SIGNAL(triggered()), this , SLOT(doAction2()));
                master->addAction(action1);
                master->addAction(action2);


krk969 2010-03-10 16:43

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Figa (Post 562716)
THX I did it but I cant see any menu. What I do have to do?

pls attach your code so somebody can try and help :)

Figa 2010-03-10 16:56

Re: Qt and Hildon menu
 
Sorry I did it too late :)

krk969 2010-03-10 17:00

Re: Qt and Hildon menu
 
as mentioned in my post above you need to do this

QMenu *menu = menuBar()->addMenu(tr("MENU TITLE"));

on a QMainWindow object to see the menu.
and then actions need to be added to this menu object.

Figa 2010-03-10 17:03

Re: Qt and Hildon menu
 
I dont understand what is menu?

krk969 2010-03-10 17:10

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Figa (Post 562733)
I dont understand what is menu?

check here
ive added more details to my previous post above

Figa 2010-03-10 21:03

Re: Qt and Hildon menu
 
Thank you, but it still doesnt work.
Code:

                QAction *action1 = new QAction(tr("&ACTION1"), this);
                QAction *action2 = new QAction(tr("&ACTION2"), this);

                QMenu *appMenu;
                appMenu = menuBar()->addMenu(tr("MENU TITLE"));
                appMenu->addAction(action1);
                appMenu->addAction(action2);

                connect(action1, SIGNAL(triggered()), this , SLOT(doAction1()));
                connect(action2, SIGNAL(triggered()), this , SLOT(doAction2()));


krk969 2010-03-11 08:18

Re: Qt and Hildon menu
 
what doesnt work, what error do you see , could you please detail so you can solicit some responses.

Figa 2010-03-11 12:48

Re: Qt and Hildon menu
 
It doesnt work because I cant see any menu on the top. Any errors.

krk969 2010-03-11 13:10

Re: Qt and Hildon menu
 
is this all done in a QMainWindow ?
attach the source file if you can.

Figa 2010-03-11 14:46

Re: Qt and Hildon menu
 
This is full code.
Code:

class Window : public QMainWindow
{
        Q_OBJECT

public:
        Window();
};

Window::Window()
    : QMainWindow()
{
        QAction *action1 = new QAction(tr("&ACTION1"), this);
        QAction *action2 = new QAction(tr("&ACTION2"), this);

        QMenu *appMenu;
        appMenu = menuBar()->addMenu(tr("MENU TITLE"));
        appMenu->addAction(action1);
        appMenu->addAction(action2);

        connect(action1, SIGNAL(triggered()), this , SLOT(doAction1()));
        connect(action2, SIGNAL(triggered()), this , SLOT(doAction2()));

        QWidget *blank = new QWidget();
        QHBoxLayout *layout = new QHBoxLayout();
        blank->setLayout(layout);
        blank->show();
}

Window window;


krk969 2010-03-11 15:09

Re: Qt and Hildon menu
 
making corrections ...
Code:

class Window : public QMainWindow
{
Q_OBJECT

public:
Window();
};

Window::Window()
: QMainWindow()
{
QAction *action1 = new QAction(tr("&ACTION1"), this);
QAction *action2 = new QAction(tr("&ACTION2"), this);

QMenu *appMenu;
appMenu = menuBar()->addMenu(tr("MENU TITLE"));
appMenu->addAction(action1);
appMenu->addAction(action2);

connect(action1, SIGNAL(triggered()), this , SLOT(doAction1()));
connect(action2, SIGNAL(triggered()), this , SLOT(doAction2()));
// add widgets to your main window once you have them, you dont need the below dummy blank widget.
// later you can do setCentralWidget(blank);


// QWidget *blank = new QWidget();
// QHBoxLayout *layout = new QHBoxLayout();
// blank->setLayout(layout);
// blank->show();

}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
       
Window window;
window.show();

return app.exec();
}


Figa 2010-03-11 15:29

Re: Qt and Hildon menu
 
Thank you. I didnt setCentraWidget.

Venemo 2010-03-24 18:35

Re: Qt and Hildon menu
 
Hi krk969!

I'm also new to Maemo and Qt.
I tried creating a window with your code. It works, but there is a side effect:

When I run the application, two menu items appear, with the name "MENU TITLE / ACTION1" and "MENU TITLE / ACTION2".
This is understandable, but what do I do if I don't want the slash signs to appear there?

krk969 2010-03-24 18:44

Re: Qt and Hildon menu
 
replace

appMenu = menuBar()->addMenu(tr("MENU TITLE"));
with
appMenu = menuBar()->addMenu(tr(""));

i dont know what i did but my previous post got replaced with this message too. but i guess you will figure it out :)

Venemo 2010-03-24 18:50

Re: Qt and Hildon menu
 
Thanks!
IT WORKS! :)

Now it is nice that this works from code, but is there any way in the UI designer to do this?
(I mean the UI designer of Qt Creator for Windows. I use MADDE.)

krk969 2010-03-24 19:10

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Venemo (Post 580803)
Thanks!
IT WORKS! :)

Now it is nice that this works from code, but is there any way in the UI designer to do this?

sorry Im old school, dont use the UI designer, prefer building my app brick by brick :p
Im sure there is, I will try it in the UI designer when I have sometime and let you know if you somebody else doesnt reply.

Venemo 2010-03-24 21:25

Re: Qt and Hildon menu
 
Thanks!

I tried it but if I remove the caption, the menu won't appear. However, your solution suits my needs, so it is enough.

By the way, how do I change the title of the dialog box which appears when I click on a QComboBox?

krk969 2010-03-24 23:02

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Venemo (Post 581025)
....how do I change the title of the dialog box which appears when I click on a QComboBox?

if you are using QT4.6 I suggest you use the QMaemo5ValueButton instead.
here's an example ( may not compile straightaway , but to give you an idea )
Code:

// the data model , which contains your list data
myListModel = new QStandardItemModel;

QStringList stringList;
stringList << "cat" << "dog" << "mouse";

foreach(QString string, stringList)
{
  QStandardItem *item = new QStandardItem(string);
  item->setTextAlignment(Qt::AlignCenter); // the Maemo 5 design spec recommends this.
  item->setEditable(false); // prevent editing of the item
  myListModel->appendRow(item);

}

// the list you see for selection
mySelectorList = new QMaemo5ListPickSelector;
mySelectorList->setModel(myListModel);

// the button itself
mySelector= new QMaemo5ValueButton("ANIMALS");
mySelector->setPickSelector(mySelectorList);

mySelector.show()

trust me this is easier than changing that title for a combobox, and will also look better for maemo :)

Venemo 2010-03-25 14:12

Re: Qt and Hildon menu
 
Actually, MADDE doesn't support Qt 4.6 yet, so I'm using 4.5...

krk969 2010-03-25 14:24

Re: Qt and Hildon menu
 
http://labs.trolltech.com/blogs/2010...so-on-windows/

besides AFAIK QT4.5 is already history. You will see it completely gone in a few days.
PR1.2 SDK is out which has QT4.6 by default, even the autobuilder is now supporting QT4.6.

Venemo 2010-03-25 17:42

Re: Qt and Hildon menu
 
Very nice, thank you!
I will check it out soon. However, the name "QMaemo5ValueButton" doesn't suggest too much portability to me.

labra 2010-04-05 06:42

Re: Qt and Hildon menu
 
Is there a way of having the "old style" menu still in QT 4.6? Porting some applications is very tricky when all normal menuitems are translated into hildon menuitems automatically (very many items in the list --> unusable).

So is there an easy way to prevent this:
http://i2.aijaa.com/b/00876/6016140.jpg

emesem 2010-06-28 11:27

Re: Qt and Hildon menu
 
Quote:

Originally Posted by Venemo (Post 580803)
Thanks!
IT WORKS! :)

Now it is nice that this works from code, but is there any way in the UI designer to do this?
(I mean the UI designer of Qt Creator for Windows. I use MADDE.)

Bringing up an old one.

I also use MADDE. In the Qt Designer you can add a menu bar to your main window by right clicking on it (in the "object/class window") and selecting menu bar. Then it will show up in the wysiwyg window. There you can change the "type here" to something valid and get your menu. In that "drop down" menu you, you have to fill in some names. If I take the examples above it would be "Action1" and "Action2".

The resulting action will be called like actionAction1 actionAction2, or so, which you than can use.

I hope this can be somehow understood (without graphics ^^).

Venemo 2010-06-28 12:23

Re: Qt and Hildon menu
 
Quote:

Originally Posted by labra (Post 595894)
Is there a way of having the "old style" menu still in QT 4.6? Porting some applications is very tricky when all normal menuitems are translated into hildon menuitems automatically (very many items in the list --> unusable).

So is there an easy way to prevent this

Yes, reduce the number if items in the menu.
Put the other functionality elsewhere - this is also required if you want your app to be finger-friendly, anyways.

Quote:

Originally Posted by emesem (Post 732501)
Bringing up an old one.

I also use MADDE. In the Qt Designer you can add a menu bar to your main window by right clicking on it (in the "object/class window") and selecting menu bar. Then it will show up in the wysiwyg window. There you can change the "type here" to something valid and get your menu. In that "drop down" menu you, you have to fill in some names. If I take the examples above it would be "Action1" and "Action2".

The resulting action will be called like actionAction1 actionAction2, or so, which you than can use.

I hope this can be somehow understood (without graphics ^^).

Thanks!
Since then, I already discovered this. But it is nice from you to answer.

Halftux 2016-12-02 19:08

Re: Qt and Hildon menu
 
Does somebody know some code to open the menubar automatically?
Or a way to update and repaint an open menubar?

I could implement a qpushbutton into the menu which lets the menu open when pressed and it should change some actions from the menu. It all does what I want but the result can only be seen by closing and reopen the menu again. I also tried to update and repaint parent widgets with no success.
In qt desktop version it is working:mad:

[edit]: So it looks like that this menu belongs to the WM, so I had to make a workaround with X11.


All times are GMT. The time now is 21:12.

vBulletin® Version 3.8.8