#include <QDockWidget>class QTextEdit;class QCloseEvent;class MessageWindow : public QDockWidget{ Q_OBJECT;public: MessageWindow(QWidget *parent = 0); // Статические функции static void Message(QString Msg, QString Marker=""); static void Clear(); static void Close(); static MessageWindow* m_msgWin;private: //static MessageWindow* m_msgWin; QTextEdit *m_text; void closeEvent(QCloseEvent *e);};
#include "app/message_window.h"#include <QTextEdit>#include <QMainWindow>MessageWindow* MessageWindow::m_msgWin = 0;MessageWindow::MessageWindow(QWidget *parent) : QDockWidget(parent){ setAllowedAreas(Qt::BottomDockWidgetArea); setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable); m_text = new QTextEdit(this); m_text->setReadOnly(true); setWidget(m_text); QSize sz = size(); sz.setHeight(100); << ----- Does not work resize(sz);}void MessageWindow::Message(QString Msg, QString Marker){ if (!m_msgWin) { m_msgWin = new MessageWindow(MainWnd); MainWnd->addDockWidget(Qt::BottomDockWidgetArea, m_msgWin); } m_msgWin->m_text->append(Msg);}void MessageWindow::Clear(){ if (m_msgWin) { m_msgWin->m_text->clear(); }}void MessageWindow::Close(){ if (m_msgWin) { m_msgWin->close(); m_msgWin = 0; }}void MessageWindow::closeEvent(QCloseEvent *e){ m_msgWin = 0;}
class CMyDock2: public QDockWidget{ Q_OBJECTpublic: CMyDock2(const QString & title, QWidget * parent = 0, Qt::WFlagsflags = 0); ~CMyDock2() {}; QSize sizeHint() const { QSize sh = QDockWidget::sizeHint(); sh.setHeight(40); return sh; }};