Results 1 to 3 of 3

Thread: Trying to overlay widget on a QTreeView item

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2011
    Posts
    60
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Trying to overlay widget on a QTreeView item

    I'm trying to align a rectangle over the text portion of a QTreeView item. Calculating the rectangle is a bit complicated because the checkbox indents add up depending on the number of parents, etc.

    So to debug this I figured I'd just draw a physical rectangle over the math prediction. However, I'm unable to render a QWidget on top of a tree view item. It never shows up. Any ideas what's wrong or how to overlay a visual over a QTreeView item?

    Basically, I want to see something like this, so I can tell where my textRect calc is off.

    caThHaZ.png

    My attempt below. I'm trying to draw the rectangle in the treeview's mousePressEvent. But, no matter what I do, the overlay widget never appears...
    Qt Code:
    1. void TreeView::mousePressEvent (QMouseEvent *event)
    2. {
    3. if (event->button() == Qt::LeftButton)
    4. {
    5. QRect textRect = QRect(checkboxX
    6. + style()->pixelMetric(QStyle::PM_IndicatorWidth)
    7. + style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing)
    8. + 30 // color chip and padding
    9. + 3, // little padding
    10. vrect.y(),
    11. treeItemWidth,
    12. vrect.height());
    13.  
    14. // Overlay colored widget to see the rectangle
    15. PaintWidget *overlay = new PaintWidget(textRect, this);
    16. overlay->repaint(); // try to force the repaint
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class PaintWidget : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit PaintWidget(const QRect &paintArea, QWidget *parent=nullptr)
    7. : QWidget(parent), m_area(paintArea)
    8. {
    9. setGeometry(m_area);
    10. QPalette pal = palette();
    11. // set white background
    12. pal.setColor(QPalette::Background, Qt::white);
    13. setPalette(pal);
    14. this->update();
    15. }
    16. ~PaintWidget(){};
    17.  
    18. private:
    19. QRect m_area;
    20. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by alketi; 29th April 2020 at 19:25.

Similar Threads

  1. Replies: 4
    Last Post: 25th August 2015, 11:12
  2. Replies: 2
    Last Post: 15th February 2011, 15:10
  3. QGraphicsscene item overlay issue
    By augusbas in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2010, 07:16
  4. Layout (widget overlay)
    By whitefurrows in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2009, 00:54

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.