2016-03-30 23 views
1

我注意到QML的StatusBar類型不包含像QStatusBar一樣的SizeGrip。帶SizeGrip的QML狀態欄

爲了獲得大小的控制權,我不得不將QML嵌入QMainWindow和QStatusBar中。雖然這有效,但它使應用程序的其他部分變得複雜,並且這不是我所追求的設計。

是否有可能通過繼承QML直接在QML中實現QStatusBar,以及QML如何識別/使用SizeGrip?

編輯: 我已經嘗試獲得QQuickPaintedItem嘗試和QML呈現QStatusBar,但到目前爲止還沒有任何運氣。在渲染調用中觸發錯誤:QCoreApplication :: sendEvent中的ASSERT失敗:「無法將事件發送給其他線程擁有的對象當前線程399d3d8。接收器'(類型'QStatusBar')在線程8c9f00」 ,文件內核\ qcoreapplication.cpp,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); 
} 

回答

0

是的,你可以從狀態欄派生自己的狀態欄QML類型或者您可以使用標準帶有您設計的contentItem的QML StatusBar。要實現大小控制,您需要將MouseArea放置在右側邊界處 - onPositionChanged中,您將發出一個由主窗口解釋爲resize命令的信號。避免反饋循環(因爲調整主窗口的大小可能會改變MouseArea的位置)作爲讀者的練習。

+0

我已經更新了這個問題,我現在正在嘗試創建一個QML QStatusBar。這主要是我關注的路徑,因爲我發現在窗口中使用MouseArea而不是QSizeGrip來調整窗口的大小並不那麼光滑。 –