0

I've created a custom Widget: in the designer and promoted a QWidget to a TreeItem (my own). But when I run the code, I can't see the widget. The only way to see it is to use setFixedSize(100, 100). Even resize and setGeometrydon't work. I want to be able to see my custom widget without giving it a fixed size.

TreeItem.h

#ifndef TREEITEM_H
#define TREEITEM_H

#include <QWidget>
#include <QRect>

class TreeItem : public QWidget
{
    Q_OBJECT
public:
    explicit TreeItem(QRect rect, QWidget *parent = nullptr);

    virtual void paintEvent(QPaintEvent*);

signals:

public slots:

protected:
    QRect m_rect;
    QFont m_font;
};

#endif // TREEITEM_H

TreeItem.cpp

#include "treeitem.h"

TreeItem::TreeItem(QRect rect, QWidget *parent): QWidget(parent)
{
    m_rect = rect;
    m_font = QFont("Arrial", 20);

    setFixedSize(100, 100); // doesn't show up without this line
}

void TreeItem::paintEvent(QPaintEvent*)
{
    QPainter painter(this);

    painter.drawLine(0, 0, 100, 100);
}
icetomtom
  • 25
  • 1
  • 5
  • how do you display this widget? via a layout? or should it be a distinct top level window? – IceFire Jan 27 '19 at 21:56
  • How do you use `TreeItem`? Please edit your question to provide a [mcve] that can be used to reproduce the problem. – G.M. Jan 27 '19 at 21:58

0 Answers0