Results 1 to 4 of 4

Thread: QTableWidget separtion lines disappearing

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidget separtion lines disappearing

    Hi,

    I have a perhaps somewhat unusual setup of a QTableWidget, where the tablewidget contains QLabels as cell-widgets, and those labels contain pixmaps to render something.
    The problem: when I drag the columnsseparator to the left, the column separation line disappears.

    I have created a simple example of the problem below. Just run it and play around with resizing the columns by dragging the header. Quickly the separation line will disappear. Screenshot:

    h2wdjy5.png

    code:

    Qt Code:
    1. class mm : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. mm(QWidget* parent = nullptr) : QWidget(parent)
    6. {
    7. setFixedSize(500,500);
    8. table.setColumnCount(2);
    9. table.setRowCount(1);
    10. table.verticalHeader()->setStretchLastSection(true);
    11.  
    12. table.setCellWidget(0, 0, l1 = new QLabel());
    13. table.setCellWidget(0, 1, l2 = new QLabel());
    14.  
    15. auto l = new QHBoxLayout();
    16. l->addWidget(&table);
    17. setLayout(l);
    18. }
    19.  
    20. QLabel *l1, *l2;
    21. QTableWidget table;
    22.  
    23. void paintEvent(QPaintEvent* e) override
    24. {
    25. {
    26. QPixmap pm(l1->size());
    27. pm.fill(Qt::red);
    28. l1->setPixmap(pm);
    29. }
    30. {
    31. QPixmap pm(l2->size());
    32. pm.fill(Qt::black);
    33. l2->setPixmap(pm);
    34. }
    35. }
    36. };
    To copy to clipboard, switch view to plain text mode 


    Why does this happen and how can I ensure the lines are always drawn?

    Happy Holidays!

  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: QTableWidget separtion lines disappearing

    Not necessarily the cause but it is usually not a good idea to override the paintEvent() method of a container.
    Especially when not calling the base implementation.

    If your cells really only contain a single color, my suggestion would be to set the background of the respective QTableWidgetItem instead.
    http://doc.qt.io/qt-5/qtablewidgetit...#setBackground

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget separtion lines disappearing

    Unfortuantley the single colors were just for demonstration.

    Thanks for the tip, but the paint-event-overriding is indeed no the cause here. Indeed the issue even occurs when I set the pixmaps only once.


    Qt Code:
    1. class mm : public QWidget
    2. {
    3.  
    4. //..as above, but without overriding paintEvent()
    5.  
    6. void init()
    7. {
    8. {
    9. QPixmap pm(l1->size());
    10. pm.fill(Qt::red);
    11. l1->setPixmap(pm);
    12. }
    13. {
    14. QPixmap pm(l2->size());
    15. pm.fill(Qt::black);
    16. l2->setPixmap(pm);
    17. }
    18. }
    19. };
    20.  
    21. ...
    22. mm m;
    23. m.show();
    24. m.init();
    25. ...
    To copy to clipboard, switch view to plain text mode 


    Do you think this might be a Qt bug?

  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: QTableWidget separtion lines disappearing

    Even if the pixmap is more complex, it make still sense to avoid cell widgets.

    Set the pixmal as each item's DecorationRole or go for a custom delegate.

    Cheers,
    _

Similar Threads

  1. qtablewidget exposed lines
    By tuli in forum Newbie
    Replies: 1
    Last Post: 25th August 2014, 12:47
  2. Replies: 1
    Last Post: 15th March 2014, 11:15
  3. Disappearing drop indicator
    By Daniel Dekkers in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2010, 11:08
  4. Disappearing widgets in QVBoxLayout
    By torleifs in forum Newbie
    Replies: 1
    Last Post: 24th October 2007, 13:17
  5. mainwindow disappearing
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2007, 09:24

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.