Another "reuse" question
-
I have a working class declared as QPlainTextEdit.
I like to add "status bar" and was looking to use multiple inheritance using QMainWindow.Coded as folloows I get an error
/mnt/A_BT_DEC10/BT__PROGRAMS/A_MAR7_MAR15/A_BT_LIBRARY/terminal_Bluetooth/console.h:79: warning: Class Console inherits from two QObject subclasses QPlainTextEdit and QMainWindow. This is not supported!
What would be another logical way to add "status bar" to existing class ?
I am asking this because
"status bar" is part of the QMainWindow and there is no .ui file. It is "added " in code , passed to class. .#ifndef CONSOLE_H #define CONSOLE_H #include <QPlainTextEdit> #include <QMainWindow> class Console : public QPlainTextEdit, public QMainWindow { Q_OBJECT signals: void getData(const QByteArray &data); public: explicit Console(QWidget *parent = nullptr); void putData(const QByteArray &data); void setLocalEchoEnabled(bool set); protected: void keyPressEvent(QKeyEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseDoubleClickEvent(QMouseEvent *e) override; void contextMenuEvent(QContextMenuEvent *e) override; private: bool m_localEchoEnabled = false; }; #endif // CONSOLE_H
-
@AnneRanch said in Another "reuse" question:
What would be another logical way to add "status bar" to existing class ?
Add a QStatusBar to the bottom
-
@JKSH OK, kindly allow me to "BUMP|".
Here is the "Console" class declaration / definition.
it is derived from QPlainTextEdit
and has NO UI
( no Console.ui ! )It is NOT related to QMainWindow which has "status bar" as standard.
This class / object is originally "embedded " in QMainWindow , actually in "mdiArea" which does have " status bar " .
I need to have similar class which is no longer part of the original mdiArea, hence I need to add "status bar" to QPlainTextEdit
QPlainTextEdit has "standard " widow title bar, but no status bar !
I was hoping for "multiple inheritance " - adding QMainWindow , but it did not work!
I believe QPlainTextEdit is derived from QWidget...
Console::Console(QWidget *parent) : QPlainTextEdit(parent) { document()->setMaximumBlockCount(100); // font here ?? document()->set QPalette p = palette(); // test chnage background color p.setColor(QPalette::Base, Qt::black); p.setColor(QPalette::Text, Qt::white); setPalette(p); //QStatusBar *pSB = new QStatusBar(); text = " TEST status tip ..... "; setStatusTip(text); text = " Console display raw serial ASCII data..."; setToolTip(text); //setstate(" TEST state "); //setState(text); }
-
Simply build a new widget, add a layout and put the QPlainTextEdit and the status bar in there.
-
@Christian-Ehrlicher ...and that is NOT what I expect from C++ " reuse " feature
Here is yet another task.
I can add messages / tool tip...Adding message into same class,
not a member of the mdiArea,puts it in the middle of the form
how do I move it to the bottom of the form - using code.?-Adding message into same class when it is a member of mdiAreaa subwidows puts the message
into main mdiArea status bar whenmouse hovers above the subwindow (status tip ?)
Console::Console(QWidget *parent) : QPlainTextEdit(parent) { document()->setMaximumBlockCount(100); // font here ?? document()->set QPalette p = palette(); // test change background color p.setColor(QPalette::Base, Qt::black); p.setColor(QPalette::Text, Qt::white); setPalette(p); //QStatusBar *pSB = new QStatusBar(); text = " TEST status tip ..... (shows in mdiArea status bar ) "; setStatusTip(text); this is the only one which does as expected text = " Console display raw serial ASCII data..."; setToolTip(text); **this message does not show anywhere** QStatusBar *pTEST = new QStatusBar(); pTEST->showMessage(" TEST status bar message "); pTEST->show();
-
-
@AnneRanch said in Another "reuse" question:
and that is NOT what I expect from C++ " reuse " feature
Then you should find another programming language or another tookit which does what you want instead.
-
@AnneRanch said in Another "reuse" question:
**this message does not show anywhere**
auto pC = new Console; // Original class auto pSB = new QStatusBar; // Additional status bar auto layout = new QVBoxLayout; layout->addWidget(pC); layout->addWidget(pSB); auto consoleWithStatusBar = new QWidget; consoleWithStatusBar->setLayout(layout); consoleWithStatusBar->show(); pSB->showMessage(" TEST status bar message ");
-
-