Results 1 to 2 of 2

Thread: Qt: Space between individual cells in QTableWidget

  1. #1
    Join Date
    Feb 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt: Space between individual cells in QTableWidget

    (Using Qt 5.5.1 on Windows 8.1)

    I have a table displaying images selected by the user.

    I know their are many other ways to display multiple images on a GUI, but I'm new to Qt, so I didn't understand how to use QGraphicsView and found the following to be the easiest way.

    But this forms a table in which images are not separated. I want some space b/w them. See how the next images starts right where the first ends.

    Capture.JPG

    How can I do it so that next image starts after leaving some space?


    Qt Code:
    1. QFileDialog dialog(this);
    2. dialog.setNameFilter(tr("Images (*.jpg)"));
    3. dialog.setFileMode(QFileDialog::ExistingFiles);
    4. QStringList all_filenames = dialog.selectedFiles();
    5. int maxCol = 3;
    6. int maxRows = all_filenames.size() / maxCol;
    7. ui->tableWidget->setColumnCount(maxCol);
    8. ui->tableWidget->setRowCount(maxRows);
    9. int remainder = all_filenames.size() % maxCol;
    10. if (remainder != 0)
    11. {
    12. maxRows +=1;
    13. }
    14. ui->tableWidget->horizontalHeader()->setDefaultSectionSize(200);
    15. ui->tableWidget->verticalHeader()->setDefaultSectionSize(200);
    16. if(all_filenames.isEmpty() == 0)
    17. {
    18. for( int i = 0; i < all_filenames.size() ; ++i)
    19. {
    20. QPixmap map(all_filenames.at(i));
    21. map = map.scaled(200,200,Qt::IgnoreAspectRatio,Q::FastTransformation);
    22. QBrush brush(map);
    23. item->setCheckState(Qt::CheckState());
    24. item->setBackground(brush);
    25. ui->tableWidget->setItem(j,k,item);
    26. k++;
    27. if ( k == maxCol )
    28. {
    29. j++;
    30. k = 0;
    31. }
    32.  
    33.  
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

  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: Qt: Space between individual cells in QTableWidget

    You set the image size to exactly the same size as the cell size.
    Have you tried making the images slightly smaller than the cell size?
    E.g. 180x180?

    Cheers,
    _

Similar Threads

  1. How to exploit all the space on QTableWidget cells
    By mcgmail in forum Qt Programming
    Replies: 2
    Last Post: 1st May 2013, 20:41
  2. QTableWidget exclusive cells
    By bwnicewo in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2012, 00:25
  3. [How to ?] Writing QTableWidget cells.
    By Rewo in forum Newbie
    Replies: 6
    Last Post: 4th April 2010, 11:00
  4. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  5. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15

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.