×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    38

    Question QListViews' QStandardItems text not displayed and more trouble

    Hi,

    I successfully created a QListView but QStandardItems don't get shown properly.
    Code:
        ui->graphicsView->setGeometry(361,0,360,640);
        appsListView = new QListView(ui->centralWidget);
        appsListView->setGeometry(0,0,360,640);
        //ui->centralWidget->setStyleSheet("QListView { background-color: yellow }");
        appsItemModel = new QStandardItemModel();
        QStandardItem appItem(QString("app"));
        appItem.setData(QString("uid"));
        appItem.setForeground(QBrush(QColor(255,255,255)));
        appsItemModel->setItem(0,&appItem);
        appsListView->setModel(appsItemModel);
        configureFor = key;
        appsListView->show();
        connect(appsListView, SIGNAL(clicked(QModelIndex)), this, SLOT(appItemClicked(QModelIndex)));
    The yellow style is a verification of the QListViews existence.

    I can even select the first and only item as its selection highlight is shown when clicking at the top of the screen, but it doesn't show text. Also the application crashes when clicking the first item.

    Code:
    void MainWindow::appItemClicked(const QModelIndex &index)
    {
        //QStandardItem* item = appsItemModel->itemFromIndex(index);
        //ui->label->setText(item->data().toString());
        disconnect(appsListView, SIGNAL(clicked(QModelIndex)), this, SLOT(appItemClicked(QModelIndex)));
        appsListView->hide();
        delete appsListView;
        delete appsItemModel;
        ui->graphicsView->setGeometry(0,0,360,640);
    }
    What's the issue here? What do I have to do to get the QStandardItem displayed properly?

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: QListViews' QStandardItems text not displayed and more trouble

    Hi,

    The application crashes because in the slot appItemClicked, you are deleting/destroying appsListView which should not be done.

    problem is not with graphicsView atleast -

    i have a piece of working code, may be you can use this to prepare yours -
    Code:
      QListView *list = new QListView();
     QSplitter splitter;
    
     splitter.addWidget( list );
    
      QStandardItemModel model( 5, 2 );
      for( int r=0; r<5; r++ )
        for( int c=0; c<2; c++)
        {
          QStandardItem *item = new QStandardItem( QString("Row:%0, Column:%1").arg(r).arg(c) );
    
          if( c == 0 )
            for( int i=0; i<3; i++ )
            {
              QStandardItem *child = new QStandardItem( QString("Item %0").arg(i) );
              child->setEditable( false );
              item->appendRow( child );
            }
    
          model.setItem(r, c, item);
        }
    
      model.setHorizontalHeaderItem( 0, new QStandardItem( "Foo" ) );
      model.setHorizontalHeaderItem( 1, new QStandardItem( "Bar-Baz" ) );
    
    
      list->setModel( &model );
     
     splitter.show();
    The above code successfully createa a listview with standard items. Usage of the same with GraphicsView also should not be an issue though i did not verify it.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    38

    Re: QListViews' QStandardItems text not displayed and more trouble

    Oh I. While I was giving the address of a QStandardItem as expected, I created the object locally. It got removed when the function exited. Creating the QStandardItem via "new" solves this issue. As the model takes ownership of the pointed object, I don't have to delete it myself.

    Thank you.
    Last edited by planetLars; 2012-02-20 at 16:31. Reason: Thanking

Similar Threads

  1. Text displayed backwards
    By pinkhardlionel in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-07-22, 17:32
  2. Replies: 1
    Last Post: 2009-04-02, 05:33
  3. Text isn't displayed properly
    By schnesim in forum Symbian
    Replies: 21
    Last Post: 2008-06-28, 08:59
  4. how to get text displayed on the screen?
    By yangym_2000 in forum Symbian
    Replies: 3
    Last Post: 2004-04-09, 12:36

Posting Permissions

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