Results 1 to 6 of 6

Thread: QTableWidgetItem visual format

  1. #1
    Join Date
    Sep 2007
    Location
    Ankara TURKEY
    Posts
    32
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableWidgetItem visual format

    1. In a TableView I have doubleSpinbox delegate, like count or money. the value comes from dataBase like numeric(10,4) I mean for example a cell seems "100000.1200", and after delegating it returns like "100000.12" or "450.0000" returns "450", that because It seems less.

    2. I need to show these cells (like in ms excel) like ###,###.## for example "12,452,231.24" and need to keep (also like excel) more digits. I mean the value "1.2445" must seems like "1.24" but when in calculation, it must have its original value.

    here is my codes:
    in the main:

    Qt Code:
    1. ...
    2. QTableWidgetItem *prof_x_miktar = new QTableWidgetItem(Proformaindex.value(6).toString());
    3. ...
    4. ProformaDelegate *spin_miktar;
    5. spin_miktar = new ProformaDelegate(tableProformaindex);
    To copy to clipboard, switch view to plain text mode 

    in the delegate (tableProformaindex):

    Qt Code:
    1. QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
    2. editor->setMaximum(4000000000);
    3. editor->setDecimals(2);
    4. return editor;
    5. ...
    6.  
    7. void ProformaDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    8. {
    9. ProformaDelegate::ProformaDelegate(QObject *parent)
    10. : QItemDelegate(parent)
    11. {
    12.  
    13. }
    14.  
    15. QWidget *ProformaDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    16. ...
    17. QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
    18. double value = index.model()->data(index, Qt::DisplayRole).toDouble();
    19. spinBox->setValue(value);
    20. }
    21.  
    22. void ProformaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    23. {
    24. QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
    25. double value = spinBox->value();
    26. model->setData(index, value, Qt::DisplayRole);
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidgetItem visual format

    QDoubleSpinBox removes group separators by default. You can enable them like shown in this thread: http://www.qtcentre.org/forum/f-qt-p...bers-8868.html
    J-P Nurmi

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

    uygar (6th October 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidgetItem visual format

    Dear All

    Actually we have another problem for this one...

    We are using a QTableWidget, for one column we bring a double value. After that we have made a delegate for this column for QSpinBox.

    What we would like to is we would like to

    1st. Bring the values to QTable like 999,999,999.00
    2nd. edit them in spin, and put it back to table 888,888,888.00
    3rd we would like to save them to sql as 888888888

    is it clear?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidgetItem visual format

    What's the problem? It gets stored as a number to the database, doesn't it? No formatting will be stored.
    J-P Nurmi

  6. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidgetItem visual format

    no formatting is going to store to database, only what we like to do is to show them like i said...

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidgetItem visual format

    You can always reimplement your model's data() and return numbers in localized format with help of QLocale. Item views localization support was significantly improved in Qt 4.3, so you could also try playing with table views locale.
    J-P Nurmi

Similar Threads

  1. Qt configure with msvc.net
    By jivanr in forum Installation and Deployment
    Replies: 1
    Last Post: 11th June 2007, 08:17
  2. Compile App using OpenGL and Visual Studios 2003
    By Rayven in forum General Programming
    Replies: 3
    Last Post: 26th April 2007, 15:43
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41
  5. Qt Designer & Visual Studio 2005
    By pSiCho in forum Qt Tools
    Replies: 6
    Last Post: 9th February 2006, 13:40

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.