I am writing a C++ Qt application with the main window that occupies the entire screen and a child window that contains simulation controls.
I'm using RHEL 7.2 with Qt 5.6. The problem is that the child window although visible in the task list, is not visible on the display.
clsMainWin::clsMainWin(QRect rctScr, QWidget *parent) : QMainWindow(parent)
,ui(new Ui::clsMainWin) {
ui->setupUi(this);
//Set-up window container background and size
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
setWindowIcon(QPixmap(1,1)));
setGeometry(rctScr);
//Display the window container
showFullScreen();
#ifdef SIM_WINDOW
mpobjSimWin = NULL;
#endif
}
void clsMainWin::paintEvent(QPaintEvent* pEvt) {
//Prevent compiler warning!
pEvt = pEvt;
//Get painter context
QPainter objPainter(this);
//Fill the root area with the chosen colour
objPainter.fillRect(geometry(),
QColor(mpobjRoot->strGetAttr(mcszXMLattrColorBg)));
#ifdef SIM_WINDOW
if ( mpobjSimWin == NULL ) {
mpobjSimWin = new clsSimWin(this);
mpobjSimWin->setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
mpobjSimWin->raise(); // for MacOS
mpobjSimWin->activateWindow(); // for Windows
}
#endif
}
Constructor snippet from simulation window:
clsSimWin::clsSimWin(QWidget *parent) : QDialog(parent)
,ui(new Ui::clsSimWin) {
assert(parent != NULL);
ui->setupUi(this);
//Set the window title
this->setStyleSheet("background-color: white;");
setWindowTitle("Data simulator");
//Set-up window
Qt::WindowFlags flags = (Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint)
& ~Qt::WindowMaximizeButtonHint;
setWindowFlags(flags);
setFixedSize(mcintWindowWidth, mcintWindowHeight);
//Display the window
show();
}
This isn't all the code, but hopefully enough to show what I've done and where the problem could be?
Fixed by moving the calls to show methods outside of the constructors.