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)

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.)


All times are GMT. The time now is 20:56.

vBulletin® Version 3.8.8