Results 1 to 4 of 4

Thread: QAbstractTableModel for continuous pixel stream

  1. #1
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QAbstractTableModel for continuous pixel stream

    I have a
    Qt Code:
    1. QList< Qvector<uint> >
    To copy to clipboard, switch view to plain text mode 
    structure to store pixel values of an image. There is a very fast image generator which continuously generates these images pixel by pixel. I need to display the pixels of the last generated image in my GUI.

    So I created a QAbstractTableModel which will reference to the last generated image. I attached a QTableView to this. A QAbstractItemDelegate is delegated to paint the individual items in the QTableView.

    Qt Code:
    1. void PixelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. if (option.state)
    4. {
    5. QColor color = index.model()->data(index, Qt::DisplayRole).value<QColor>();
    6. painter->fillRect(option.rect, color);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Basically I am using QTableView to display an image! I also add this QTableView to a graphicsScene to zoom in and out of image etc. So I need to resize my QTableView everytime the size of the generated image changes to avoid scrollbars.

    Question:
    Looks like I am complicating things way too much for no reason?! Any suggestion would be useful.

    Regards
    Vikram

  2. #2
    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: QAbstractTableModel for continuous pixel stream

    Why not just write into a QImage and display that?

    Cheers,
    _

  3. #3
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QAbstractTableModel for continuous pixel stream

    Thanks @anda_skoa.

    But why doesn't Qt suppor something like a "QImageView"!!
    I mean I wanted to use Qt's Model-View architecture for displaying pixel data from the data model to the GUI. I now decided to just send a signal from the data model to the GUI at fixed intervals (slower than the data being written by my fast Image Generator!). The GUI then maps these pixel values to QImage and then sets the pixmap of a QGraphicsPixmapItem that I have placed in my graphics scene.

    The processing in the GUI takes about 5-7 milliseconds depending on the size of the image since each pixel value is mapped to RGB:

    Qt Code:
    1. QList< QVector<uint> > dataModelImage;
    2. int minPixVal; // say 0.. depends on the image
    3. int maxPixVal; // say 65535.. depends on the image
    4.  
    5. QImage newImg(dataModelImage[0].size(), dataModelImage.size(), QImage::Format_RGB16);
    6.  
    7. // For each row
    8. for(int i=0; i<dataModelImage.size(); ++i)
    9. {
    10. // For each column
    11. for(int j=0; j<dataModelImage[i].size(); ++j)
    12. {
    13. double ratio = (double)(dataModelImage[i][j] - minPixVal) / (maxPixVal - minPixVal);
    14. int rgbVal = ratio*255;
    15. newImg.setPixel(j, i, qRgb(rgbVal,rgbVal,rgbVal));
    16. }
    17. }
    18.  
    19. m_pixmapItem->setPixmap(QPixmap::fromImage(newImg));
    To copy to clipboard, switch view to plain text mode 

    I can live with 5-7 milliseconds for now. But isn't it way too much?

    Regards
    Vikram

  4. #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: QAbstractTableModel for continuous pixel stream

    Quote Originally Posted by Vikram.Saralaya View Post
    But why doesn't Qt suppor something like a "QImageView"!!
    There are many classes that can be a "QImageView", e.g. QLabel, QPixmapItem in a QGraphicsView, any custom widget using QPainter, etc.

    Quote Originally Posted by Vikram.Saralaya View Post
    I mean I wanted to use Qt's Model-View architecture for displaying pixel data from the data model to the GUI.
    Why, which of the model/view features do you need?

    Quote Originally Posted by Vikram.Saralaya View Post
    The processing in the GUI takes about 5-7 milliseconds depending on the size of the image since each pixel value is mapped to RGB:
    Just some ideas:
    - you seem to allocate a new image every time
    - you are using two nested loops instead of scanline() or bits() for direct data access
    - if you use the same value for red/green/blue, isn't that a grayscale image? In which case an image with a color table might be faster

    Cheers,
    _

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

    Vikram.Saralaya (31st July 2015)

Similar Threads

  1. Replies: 0
    Last Post: 1st February 2014, 17:35
  2. Filling a pie pixel by pixel
    By pradhan in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2013, 09:33
  3. Replies: 2
    Last Post: 17th February 2012, 00:10
  4. Continuous Printing
    By Prabha in forum General Discussion
    Replies: 0
    Last Post: 28th July 2010, 12:01
  5. QPixmap pixel by pixel ?
    By tommy in forum Qt Programming
    Replies: 19
    Last Post: 3rd December 2007, 23:52

Tags for this Thread

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.