Results 1 to 4 of 4

Thread: Visualising data from mysql table

  1. #1
    Join Date
    Jul 2013
    Posts
    22
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Visualising data from mysql table

    For the purpose of visualizing data from a MySQL table, a QTableView is being used in conjunction with a QSqlTableModel. As the intention is not to edit the values then the QTableView is configured with:
    Qt Code:
    1. ui->tbViewTmHistTk->setEditTriggers(QAbstractItemView::NoEditTriggers);
    To copy to clipboard, switch view to plain text mode 
    Is this a good approach in order to prevent editing the data?
    Last edited by vrltwe; 28th December 2013 at 16:51. Reason: reformatted to look better

  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: Visualising data from mysql table

    Yes, but the model remains editable in any view that allows editing. QSqlQueryModel gives you a truly read-only model.

  3. The following user says thank you to ChrisW67 for this useful post:

    vrltwe (31st December 2013)

  4. #3
    Join Date
    Jul 2013
    Posts
    22
    Thanks
    10
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Visualising data from mysql table

    Ok, I understand.

    I think QSqlTableModel was used because it enables changing the color of items, re-writing the data function.
    Qt Code:
    1. QVariant SqlTableModelTk::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant value = QSqlTableModel::data(index, role);
    4. if ( role == Qt::TextColorRole )
    5. if( (index.column(), index.row()) )
    6. return QVariant::fromValue(QColor(Qt::red));
    7. return value;
    8. }
    To copy to clipboard, switch view to plain text mode 
    As it doesn't exist a data function for QSqlQueryModel then I suppose I'm in the correct direction. Is there another approach which could be applied in order to attend both requirements, change item color and prevent editing the database?

    Thanks for the attention.
    Last edited by vrltwe; 30th December 2013 at 17:04. Reason: spelling corrections

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Visualising data from mysql table

    QSqlQueryModel is a subclass of QAbstractItemModel, so it has a data() method.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    vrltwe (31st December 2013)

Similar Threads

  1. Replies: 1
    Last Post: 8th June 2011, 14:13
  2. unable to insert into mysql table
    By mohanakrishnan in forum Newbie
    Replies: 4
    Last Post: 5th December 2009, 05:02
  3. sort mysql table
    By eleanor in forum Qt Programming
    Replies: 2
    Last Post: 10th October 2007, 16:42
  4. get mysql table into QComboBox
    By eleanor in forum Qt Programming
    Replies: 17
    Last Post: 10th October 2007, 15:35
  5. MYSQL 5 Table qt model as small Mysql admin
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 09:43

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.