2

I notice that QML's StatusBar type doesn't include the SizeGrip like QStatusBar does.

In order to get a size grip, I had to instead embed the QML into a QMainWindow with a QStatusBar. Although this works, it complicates the rest of the app and it's not really the design I'm after.

Would it be possible to implement the QStatusBar directly in QML by subclassing it and how would QML be able to recognise/use the SizeGrip?

EDIT: I've attempted to derive QQuickPaintedItem to try and render a QStatusBar in QML, but so far haven't had any luck. An error is being triggered in the render call: ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 399d3d8. Receiver '' (of type 'QStatusBar') was created in thread 8c9f00", file kernel\qcoreapplication.cpp, line 553

.h

class WindowStatusBar : public QQuickPaintedItem
{
    Q_OBJECT
public:
    explicit WindowStatusBar(QQuickItem *parent = 0);
    virtual ~WindowStatusBar();

    void paint(QPainter *painter);

protected:
    QStatusBar *statusBar_;
};

.cpp

WindowStatusBar::WindowStatusBar(QQuickItem *parent)
    : QQuickPaintedItem(parent)
    , statusBar_(NULL)
{
    setOpaquePainting(true);
    setAcceptHoverEvents(true);
    setAcceptedMouseButtons(Qt::AllButtons);

    statusBar_ = new QStatusBar;
}

WindowStatusBar::~WindowStatusBar()
{
    delete statusBar_;
}

void WindowStatusBar::paint(QPainter *painter)
{
    statusBar_->render(painter, QPoint(), QRegion(),
        QStatusBar::DrawWindowBackground | QStatusBar::DrawChildren);
}
gwarn
  • 136
  • 1
  • 7

1 Answers1

0

Yes, you can derive your own statusbar QML type from StatusBar or you can use the standard QML StatusBar with a contentItem that you designed. To implement the size grip you would put a MouseArea at the right border- in the onPositionChanged you would emit a signal that is interpreted by the mainwindow as a resize command. Avoiding feedback loops (because resizing the main window may change the position in the MouseArea) is left as an exercise for the reader.

hmuelner
  • 8,093
  • 1
  • 28
  • 39
  • I've updated the question with my current attempt at creating a QML QStatusBar. This is mainly the path I am focusing on because I was finding that the resizing of the window is not nearly as smooth using a MouseArea instead of a QSizeGrip in a window. – gwarn Apr 05 '16 at 04:20