Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. QButton dentro QWebEngineView
Forum Updated to NodeBB v4.3 + New Features

QButton dentro QWebEngineView

Scheduled Pinned Locked Moved Solved Italian
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bruschetta
    wrote on last edited by Bruschetta
    #1

    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();
    }
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bruschetta
      wrote on last edited by
      #2

      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"?

      VRoninV 1 Reply Last reply
      0
      • B Bruschetta

        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"?

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3
        • Cambia QPushButton quit( "X", 0 ); in QPushButton quit( "X", &view);
        • aggiungi quit.show();

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        B 1 Reply Last reply
        1
        • VRoninV VRonin
          • Cambia QPushButton quit( "X", 0 ); in QPushButton quit( "X", &view);
          • aggiungi quit.show();
          B Offline
          B Offline
          Bruschetta
          wrote on last edited by Bruschetta
          #4

          Perfetto! Grazie VRonin :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved