/* Bug-Description: If a window has no titlebar and there is an ActiveX-Control other Widgets (e.g. QLineEdit) are not painted any more. However, other events (like KeyPress, ...) are handled correctly. Description: Small test-programm, which shows ActiveX-Control Bug. Steps to produce: 1) Click "Toggle Titlebar" 2) Enter something in the Edit-Box => nothing is displayed 3) Click "Toggle Titlebar" again => entered text is visible Compile: qtBase= qtInclude=$qtBase/include qtLib=$qtBase/lib cl -nologo activex-bug.cc -MD \ \ -I$qtInclude \ -I$qtInclude/QtGui \ -I$qtInclude/QtCore \ -I$qtInclude/QtWidgets \ -I$qtInclude/QtAngle \ -I$qtInclude/ActiveQt \ \ $qtLib/qtmain.lib \ $qtLib/Qt5Core.lib \ $qtLib/Qt5Widgets.lib \ $qtLib/Qt5Gui.lib \ $qtLib/Qt5AxBase.lib \ $qtLib/Qt5AxContainer.lib \ \ user32.lib gdi32.lib kernel32.lib Ole32.lib OleAut32.lib -Feactivex-bug.exe Docu: from: http://www.qtforum.org/article/17217/error-class-qapplication-has-no-member-named-setmainwidget.html http://doc.qt.io/qt-5/activeqt-index.html http://www.qtforum.org/article/22777/embedding-media-player-in-qt-application.html Maybe QWidget::DrawChildren 0x2 If you enable this option, the widget's children are rendered recursively into the target. By default, this option is enabled. is switched off? (see http://doc.qt.io/qt-4.8/qwidget.html) */ #include #include #include #include #include #include #include #include #include #include #include #include #include /* std::string eventTypeToString(QEvent::Type type) { // from: http://stackoverflow.com/questions/22535469/how-to-get-human-readable-event-type-from-qevent static int eventEnumIndex = QEvent::staticMetaObject.indexOfEnumerator("Type"); return QEvent::staticMetaObject.enumerator(eventEnumIndex).valueToKey(type); } */ // //////// class MyButton : public QPushButton { public: MyButton(const QString & text, std::function _cb) : QPushButton(text), cb(_cb) { // v- https://wiki.qt.io/How_to_Use_QPushButton/de // ST: works only with moc-Compiler //QObject::connect(this, SIGNAL(clicked()), qApp, SLOT(cb())); } virtual bool event(QEvent * e) override { if ( e->type() == QEvent::MouseButtonRelease ) { QMouseEvent *me = (QMouseEvent *)e; if ( hitButton(me->pos()) ) { cb(); } } //std::cout << "button event; type=" << e->type() << " " << eventTypeToString(e->type()) << "\n"; return QPushButton::event(e); } private: std::function cb; }; // //////// void toggleTitleBar(QWidget *widget, bool titleBar) { // v- stolen from: d:\Repository\WinccOA-Branch3.14\src\Exe\UiQT\Shapes\ShapeExtHdl.cxx QPoint p(widget->pos()); Qt::WindowFlags flags = widget->windowFlags(); if ( !titleBar ) { // keep only "stay on top" flag flags &= (Qt::WindowStaysOnTopHint | Qt::WindowType_Mask); flags |= Qt::FramelessWindowHint; } else { // keep only "stay on top" flag flags &= (Qt::WindowStaysOnTopHint | Qt::WindowType_Mask); } widget->setWindowFlags(flags); widget->move(p); widget->show(); } // //////// int main( int argc, char **argv ) { QApplication app(argc,argv); QMainWindow win; bool titleBar = true; QVBoxLayout *vbox = new QVBoxLayout(); // ActiveX-Control { QAxWidget* widget = new QAxWidget(); widget->setControl("WMPlayer.OCX"); //widget->dynamicCall("Navigate(const QString&)", QString("http://qtcentre.org")); vbox->addWidget(widget); } // Edit+Label { QHBoxLayout *hbox = new QHBoxLayout(); hbox->addWidget(new QLabel("edit1: ", 0)); hbox->addWidget(new QLineEdit("abc")); QWidget *hboxWidget = new QWidget(); hboxWidget->setLayout(hbox); vbox->addWidget(hboxWidget); } // Buttons { QHBoxLayout *hbox = new QHBoxLayout(); //hbox->addWidget(new QPushButton(" Okay ")); //hbox->addWidget(new QPushButton(" Cancel ")); hbox->addWidget(new MyButton(" Toggle Titlebar ", [&win, &titleBar]() { std::cerr << "toggle title\n"; titleBar = !titleBar; toggleTitleBar(&win, titleBar); })); hbox->addWidget(new MyButton(" Quit ", [&app]() { std::cerr << "quit pressed\n"; app.exit(); })); QWidget *hboxWidget = new QWidget(); hboxWidget->setLayout(hbox); vbox->addWidget(hboxWidget); } // main { QWidget *vboxWidget = new QWidget(); vboxWidget->setLayout(vbox); win.setCentralWidget(vboxWidget); } win.show(); return app.exec(); }