QButton dentro QWebEngineView
Solved
Italian
-
Sto ancora lavorando sull'esempio minimal del QWebEngineView e adesso sto cercando di inserire un bottone all'interno dellaview stessa.
Siccome la mia view è borderless e quindi senza presenza di tasti "per chiudere" vorrei appunto inserire un piccolo bottone per poter chiudere l'app.E' possibile ottenere questo risultato?Avete consigli? Grazie per il tempo e le eventuali risposte
Watcher::Watcher(QObject *parent) : QObject(parent) { } void Watcher::onFocusChanged(QWidget * old, QWidget * now) { Q_UNUSED(old); QWidget * window; if (now == 0) { window = 0; } else { window = now->window(); } if (window != 0) { qDebug() << window->windowTitle(); } else { qDebug() << "No active window"; exit (EXIT_FAILURE); } } QUrl commandLineUrlArgument() { const QStringList args = QCoreApplication::arguments(); for (const QString &arg : args.mid(1)) { if (!arg.startsWith(QLatin1Char('-'))) return QUrl::fromUserInput(arg); } return QUrl(QStringLiteral("https://www.hdblog.it")); } int main(int argc, char *argv[]) { QApplication app(argc, argv); Watcher watcher; QObject::connect( &app, SIGNAL(focusChanged(QWidget*,QWidget*)), &watcher, SLOT(onFocusChanged(QWidget*,QWidget*))); QWebEngineView view; view.setUrl(commandLineUrlArgument()); if(argc>1) { int x = atoi(argv[2]); int y = atoi(argv[3]); view.resize(x, y); }else{ view.resize(1024, 750); } if(argc>3){ int x = atoi(argv[4]); int y = atoi(argv[5]); view.move(x,y); }else{ view.move(0,0); } view.setWindowFlags(Qt::WindowStaysOnTopHint); view.setWindowFlags(Qt::CustomizeWindowHint); view.setWindowFlags(Qt::FramelessWindowHint); view.show(); return app.exec(); }
-
Utilizzando
QPushButton quit( "X", 0 ); quit.resize( 30, 30 ); quit.setFont( QFont( "Times", 18, QFont::Bold ) ); QObject::connect( &quit, SIGNAL(clicked()), &app, SLOT(quit()) ); quit.show();
Riesco a fare il bottone come voglio , però sono due widget diversi e questo mi va a rendere inutile il watcher che mi controlla se il browser è sempre "on top".
Posso incapsulare il bottone "quit" dentro la QApplication "app" in modo che siano "sul solito piano"? -
- Cambia
QPushButton quit( "X", 0 );
inQPushButton quit( "X", &view);
- aggiungi
quit.show();
- Cambia
-
Perfetto! Grazie VRonin :)