Results 1 to 4 of 4

Thread: Simple Table View

  1. #1
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Simple Table View

    I'm translating a little app that I made in PHP-Gtk to Qt. I was going well till I had to do what in Gtk is a GtkTreeView, but in Qt I guess it's a QTableView or a QTableWidget, I don't know which one to use. Basically it has 3 columns (Accounts, Password, Group Id) and must have the option to sort the items asc/desc. Here is a pic of my app:



    If you double-click any item, the entries below will be filled according to the item you cliked.
    If you click Prev/Next buttons, it will clear the list and add the new items.

    I'm really lost because:
    1. I dont know what is better to my case: QTableView or QTableWidget
    2. I couldn't test any of both, since I didn't find any simple example to newbies

    So... could someone show me how to do a simple table like in the pic? All the examples I found were difficult.

    Thanks

    PS: (I just want the table, forget the other widgets)

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Simple Table View

    Please edit your post and upload the image to this site before a moderator finds and deletes it.

    Where is the data in the table coming from? Is it fixed or variable?

  3. #3
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Simple Table View

    Quote Originally Posted by ChrisW67 View Post
    Please edit your post and upload the image to this site before a moderator finds and deletes it.

    Where is the data in the table coming from? Is it fixed or variable?
    From a variable. A friend told me to use QTreeView instead of QTables, but I'm still lost...

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Simple Table View

    You can use either. The QTableView can source its data from any Qt data model (you might look a QStandardItemModel). The QTableWidget is a QTableView with its own internal data model. Search for Model/View Programming in the Qt documentation to get an overview of how this works.

    To use the QTableWidget need to insert your values using QTableWidget::setItem(). You create and remove rows in the table with QTableWidget::insertRow() and QTableWidget::removeRow(). You enable sorting with setSortingEnabled(). You can used the currentChanged() signal from the QTableWidget's selectionModel() to trigger updates of the other widgets.

Similar Threads

  1. How to make a simple table and calculate col sums?
    By teele in forum Qt Programming
    Replies: 4
    Last Post: 19th January 2011, 22:34
  2. Replies: 5
    Last Post: 3rd April 2010, 04:07
  3. Replies: 0
    Last Post: 8th July 2009, 11:01
  4. Table view
    By tulsi in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2009, 08:07
  5. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.