Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, January 2008
Specific columns in QColumnView


Message 1 in thread

Hi All,

I want to use QColumnView to view a specified columns from a table of 
database, *How I can do this?*

------------------------------------------------------------------------

I tired to use the following code, but it didn't specify columns view as 
I need
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(dbPath);
    if (!dbPath.isEmpty()) {
        if(db.open())
        {
            QSqlTableModel *model = new QSqlTableModel(this, db);
            model->setTable("table1");
            model->select();
            ui.columnView->setModel(model);
        }
    }

-- 
 [ signature omitted ] 

Message 2 in thread

On Jan 9, 2008, at 7:29 AM, M. Bashir Al-Noimi wrote:

> Hi All,
>
> I want to use QColumnView to view a specified columns from a table  
> of database, How I can do this?
>
>
> I tired to use the following code, but it didn't specify columns  
> view as I need

What exactly are you trying to do, and what result did you get? I  
normally use either a QTreeView or QTableView to view multiple columns  
in a database, or QListView to only display one column. While I have  
never used QColumnView for anything, from the description it would  
appear it is more of a hierarchical browser than a straight data  
display widget, and as such needs a hierarchy in the data model to  
work. Your code is simply populating the model with all the columns  
from table1 in your database, so there would be no hierarchy for the  
QColumnView to browse, and as such it would seem that a QTableView or  
QTreeView would be more appropriate. Or maybe that's the problem and I  
just don't understand what you are trying to accomplish? I hope this  
is of some help.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

>
>     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
>     db.setDatabaseName(dbPath);
>     if (!dbPath.isEmpty()) {
>         if(db.open())
>         {
>             QSqlTableModel *model = new QSqlTableModel(this, db);
>             model->setTable("table1");
>             model->select();
>             ui.columnView->setModel(model);
>         }
>     }
>
> -- 
> Best Regards ØØÙØØÙ
> Muhammad Bashir Al-Noimi ÙØÙØ ØØÙØ ØÙÙØÙÙÙ
>
> My Blog ÙØÙÙØÙ
> http://mbnoimi.net/