×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Nokia Developer Expert
    Join Date
    Jun 2009
    Posts
    36

    Question Picklist example as application

    Hi,

    I'm redesigning my UI to make use of the new Maemo5 buttons etc and thought I'd start by taking the picklist example (http://qt.nokia.com/doc/qt-maemo-4.6...kselector.html) and modifying it to use a QMainWindow.

    The original code compiles and runs fine.

    creating a class thus:

    class MainWindow : public QMainWindow {
    Q_OBJECT
    public:
    MainWindow(QWidget *parent = 0);
    ....

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)

    {
    /// Test example
    QStandardItemModel model(0, 1);
    populateListModel(&model);

    QVBoxLayout *layout = new QVBoxLayout;

    QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value besides text");
    button3->setValueLayout(QMaemo5ValueButton::ValueBesideText);
    QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
    selector1->setModel(&model);
    // not setting the current index means that the value is empty.
    //selector1->setCurrentIndex(1);
    button3->setPickSelector(selector1);
    layout->addWidget(button3);

    button3->show();
    }

    Results in a window with no content but a title bar. using setLayout(layout) fails as QMainWindow has a defined layout.

    Setting it up as a QDialog based class results in a small (half screen window) with no content.

    Defining a new central QWidget thus...

    QWidget *mainMan = new QWidget(this);
    QMainWindow::setCentralWidget( mainMan);

    QStandardItemModel model(0, 1, mainMan);
    populateListModel(&model);

    QVBoxLayout *layout = new QVBoxLayout (mainMan);

    QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value besides text");
    button3->setValueLayout(QMaemo5ValueButton::ValueBesideText);
    QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
    selector1->setModel(&model);
    // not setting the current index means that the value is empty.
    //selector1->setCurrentIndex(1);
    button3->setPickSelector(selector1);

    layout->addWidget(button3);
    mainMan->setLayout(layout);
    mainMan->show();

    Results in the button being displayed fine but when selected displays a half size empty window rather than a pick list. I've tried to set the parent on the ValueButton and PickSelector but this has no effect.

    This may be my ignorance on the window relationships or on QT generally but help and comment much appreciated. Advice on how to add a set of stacked windows with defined child widgets in each would be appreciated as, again, using the canned example doesn't work in the above MainWindow class definition even trying to be careful with parent/child relationships.

    BR David

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Picklist example as application

    So you create model on the stack and it's destroyed, when constructor quits. You have to create it dynamically using operator new.

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2009
    Posts
    36

    Smile Re: Picklist example as application

    Brilliant.

    creating the model via new worked a treat.

    Many thanks as always.

    BR
    David

  4. #4
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Picklist example as application

    Quote Originally Posted by davidmct View Post
    Brilliant.

    creating the model via new worked a treat.

    Many thanks as always.

    BR
    David
    Make sure you are passing this to constructor QStandardItemModel, otherwise you will have memory leak.

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2009
    Posts
    36

    Re: Picklist example as application

    Hi,

    Can I just clarify. At the moment mainMan is a child widget of the application. I use new with mainMain then as the parent for QStandardItemModel:

    QStandardItemModel *model = QStandardItemModel (0,1, mainMan);

    I assume this will avoid a memory leak as mainMan takes control/ownership. Is that correct?

    I'm using mainMan so I can control the layout within the main application window. Is there another way to set a layout in QMainWindow?

    Many thanks,

    David

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Picklist example as application

    Quote Originally Posted by davidmct View Post
    Can I just clarify. At the moment mainMan is a child widget of the application. I use new with mainMain then as the parent for QStandardItemModel:

    QStandardItemModel *model = QStandardItemModel (0,1, mainMan);

    I assume this will avoid a memory leak as mainMan takes control/ownership. Is that correct?
    I cannot say without a context. However, normally in constructor you use this.

    Quote Originally Posted by davidmct View Post
    I'm using mainMan so I can control the layout within the main application window. Is there another way to set a layout in QMainWindow?
    You should use QMainWindow::setCentralWidget() as QMainWindow has a layout already.
    Code:
    QVBoxLayout *layout = new QVBoxLayout;
    // add some widgets to layout
    setCentralWidget(new QWidget);
    centralWidget()->setLayout(layout);

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2009
    Posts
    36

    Re: Picklist example as application

    Hi,

    I understand and your code is neater than mine and has same effect. However, if I want my central widget to have stacked windows then how would I approach this?

    If I use my approach of

    QWidget *mainMan = new QWidget(this);
    QMainWindow::setCentralWidget( mainMan);
    mainMan->setAttribute(Qt::WA_Maemo5StackedWindow);

    I assume I can add another stacked window using ...

    QPushButton button2("Click here to open another stacked window", mainMan);
    button2.setAttribute(Qt::WA_Maemo5StackedWindow);
    button2.setWindowFlags(button2.windowFlags() | Qt::Window);

    I can then show these windows using show().

    In your suggestion of

    QVBoxLayout *layout = new QVBoxLayout;
    // add some widgets to layout
    setCentralWidget(new QWidget);
    centralWidget()->setLayout(layout);

    Could I have a set of layouts that I can overlay on the centralWidget by repeatedly calling setLayout? How else could I achieve this?

    What I'm trying to achieve is an initial window with a number of buttons which when clicked bring up new windows containing new layouts. QDialog might achieve this effect as various data are to be entered but I prefer the look of sliding windows and persistence of information.

    Hope this makes sense
    Thanks,
    David

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Picklist example as application

    Quote Originally Posted by davidmct View Post
    I understand and your code is neater than mine and has same effect.
    Almost.

    Quote Originally Posted by davidmct View Post
    QWidget *mainMan = new QWidget(this);
    QMainWindow::setCentralWidget( mainMan);
    mainMan->setAttribute(Qt::WA_Maemo5StackedWindow);
    This will compile but makes no sense. You set Qt::WA_Maemo5StackedWindow attribute to windows only.
    You don't need QMainWindow::

    Quote Originally Posted by davidmct View Post
    QPushButton button2("Click here to open another stacked window", mainMan);
    button2.setAttribute(Qt::WA_Maemo5StackedWindow);
    button2.setWindowFlags(button2.windowFlags() | Qt::Window);
    This is wrong since mainMan is not a window. Making window from button is also Ok, but probably you never do that in real life.
    There is an example here:
    http://wiki.forum.nokia.com/index.ph...ows_in_Maemo_5

    Quote Originally Posted by davidmct View Post
    Could I have a set of layouts that I can overlay on the centralWidget by repeatedly calling setLayout? How else could I achieve this?
    What will happen, if you repeatedly call setLayout is written in documentation.
    http://qt.nokia.com/doc/4.6/qwidget.html#setLayout

Similar Threads

  1. Can't capture keypress in background application
    By Jick in forum Symbian User Interface
    Replies: 4
    Last Post: 2010-04-07, 05:39
  2. Not able to install application in mobile.
    By SymbianTH in forum Symbian
    Replies: 2
    Last Post: 2009-10-08, 11:34
  3. Want to run a j2me application from symbian
    By joy.mca in forum Symbian
    Replies: 15
    Last Post: 2009-09-12, 12:32
  4. AutoStart My application at bootup
    By prakashs in forum Symbian
    Replies: 7
    Last Post: 2009-03-24, 10:06
  5. Replies: 1
    Last Post: 2008-05-08, 12:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×