Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to put a layout over a fullscreen item?
Forum Updated to NodeBB v4.3 + New Features

How to put a layout over a fullscreen item?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by Violet Giraffe
    #1

    I want to have a set of buttons "floating" over a full-screen item at the bottom, overlapping it. Can this be done?

    raven-worxR 1 Reply Last reply
    0
    • V Violet Giraffe

      I want to have a set of buttons "floating" over a full-screen item at the bottom, overlapping it. Can this be done?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      Edit: sorry, i have seen afterwards that you are looking for a QML solution.

      @Violet-Giraffe
      something like this is a possibility (untested):

      class MyButtonPanel : public QFrame
      {
      public:
          MyButtonPanel( QWidget* fullScreenWidget )
              : QFrame( fullScreenWidget, Qt::Window )
          {
                 fullScreenWidget->installEventFilter( this );
          }
      
          virtual bool eventFilter( Qobject* watched, QEvent* event )
          {
                 switch( event->type() )
                 {
                      case QEvent::Resize:
                      case QEvent::Move:
                            this->updatePosition();
                      break;
                 return QFrame::eventFilter( watched, event );
          }
      
      protected slots:
            void updatePosition()
            {
                   if( this->isHidden() )
                         return;
      
                   QWidget* fullScreenWidget = this->parentWidget();
                   QRect globalRect = fullScreenWidget->rect();
                        globalRect->moveTopLeft( fullScreenWidget->mapToGlobal( QPoint(0,0) );
      
                   QRect geometry = this->geometry();
                   geometry.moveBottomRight( globalRect.bottomRight() - QPoint(20,20) );
                   this->setGeometry( geometry );
            }
      };
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      V 1 Reply Last reply
      0
      • raven-worxR raven-worx

        Edit: sorry, i have seen afterwards that you are looking for a QML solution.

        @Violet-Giraffe
        something like this is a possibility (untested):

        class MyButtonPanel : public QFrame
        {
        public:
            MyButtonPanel( QWidget* fullScreenWidget )
                : QFrame( fullScreenWidget, Qt::Window )
            {
                   fullScreenWidget->installEventFilter( this );
            }
        
            virtual bool eventFilter( Qobject* watched, QEvent* event )
            {
                   switch( event->type() )
                   {
                        case QEvent::Resize:
                        case QEvent::Move:
                              this->updatePosition();
                        break;
                   return QFrame::eventFilter( watched, event );
            }
        
        protected slots:
              void updatePosition()
              {
                     if( this->isHidden() )
                           return;
        
                     QWidget* fullScreenWidget = this->parentWidget();
                     QRect globalRect = fullScreenWidget->rect();
                          globalRect->moveTopLeft( fullScreenWidget->mapToGlobal( QPoint(0,0) );
        
                     QRect geometry = this->geometry();
                     geometry.moveBottomRight( globalRect.bottomRight() - QPoint(20,20) );
                     this->setGeometry( geometry );
              }
        };
        
        V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        @raven-worx
        Thanks, but I meant QML - this is the Qt Quick section, didn't think I need to specify :)

        raven-worxR 1 Reply Last reply
        0
        • V Violet Giraffe

          @raven-worx
          Thanks, but I meant QML - this is the Qt Quick section, didn't think I need to specify :)

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Violet-Giraffe
          yes, my fault.
          I realized it after i made the post.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by Violet Giraffe
            #5

            I think anchors is the way to go. Works like charm:

            import QtQuick 2.7
            import QtQuick.Controls 2.0
            import QtQuick.Layouts 1.3
            import ReaderView 1.0
            
            ApplicationWindow {
                id: window
            
                CReaderView {
                    anchors.fill: parent
                    id: readerView
                }
            
                Button {
                    anchors.bottom: readerView.bottom
                    anchors.horizontalCenter: readerView.horizontalCenter
            
                    width: 64
                    height: 64
                    text: "Start"
                }
            }
            

            I haven't tested with a Layout instead of Button, but hope it'll work.
            Oddly enough, if I anchor to window instead of readerView (which seems more logical because that's what I want to do semantically), it doesn't work right.

            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