Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Move QWidget offscreen on linux?
QtWS25 Last Chance

Move QWidget offscreen on linux?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwidgetx11window manager
5 Posts 4 Posters 1.6k 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.
  • I Offline
    I Offline
    IMAN4K
    wrote on 22 Aug 2019, 14:13 last edited by
    #1

    Hi everyone.
    In some cases, we need to move QWidget outside the screen coordinate (move it with negative pos), but this behavior is not working under X11 platform(tested under ubuntu 18.04).

    Is it related to window manager or Qt?
    What is the solution for this?

    Related:

    • Qt 4.7.0 & Ubuntu 10.10: Cannot move application window out of desktop bounds

    Regards.

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Aug 2019, 19:16 last edited by
      #2

      Hi,

      Can you explain what cases these are ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        IMAN4K
        wrote on 22 Aug 2019, 20:10 last edited by
        #3

        Hi @SGaist
        Consider the situation when we use qtvirtualkeyboard in widget-based applications. when the virtual keyboard or onscreen keyboard is shown(click or touch on input widget) user expect to see what he/she is typing inside the input widget(see the input widget itself like Android Swiftkey) so it comes to mind that the input widget container(parent widget) should move off the screen whenever needed(input widget.rect().bottom() is greater than keyboard.rect().top())
        The expected behavior:
        alt text

        And here is my implementation:

        class LineEdit :public QLineEdit {
            Q_OBJECT
        
        public:
            LineEdit(QWidget *parent = nullptr);
            LineEdit(const QString&, QWidget *parent = nullptr);
        
        protected:
            bool event(QEvent*) override;
        
        private:
            bool _moved = false;
            int _lastDiff = 0;
        };
        
        LineEdit::LineEdit(QWidget *parent) :QLineEdit(parent) {
            setAttribute(Qt::WA_InputMethodEnabled, true);
            setInputMethodHints(inputMethodHints() | Qt::InputMethodHint::ImhDigitsOnly);
        }
        
        LineEdit::LineEdit(const QString& txt, QWidget *parent) : QLineEdit(txt, parent) {
            setAttribute(Qt::WA_InputMethodEnabled, true);
            setInputMethodHints(inputMethodHints() | Qt::InputMethodHint::ImhDigitsOnly);
        }
        
        bool LineEdit::event(QEvent* e) {
            const auto keyboard_rect = QGuiApplication::inputMethod()->keyboardRectangle();
            const auto keyboard_visible = QGuiApplication::inputMethod()->isVisible();
            const auto global_y = QWidget::mapToGlobal(rect().topLeft()).y() + height();
            const auto k_global_y = keyboard_rect.topLeft().y();
            const auto diff = k_global_y - global_y;
            const auto need_to_move = diff < 0;
        
            /* move main widget */
            if (keyboard_visible && !_moved && need_to_move) {
                _moved = true;
                _lastDiff = diff;
                const auto g = parentWidget()->frameGeometry();
                parentWidget()->move(g.x(), g.y() - qAbs(_lastDiff));
            }
            /* roll back */
            if (!keyboard_visible && _moved) {
                _moved = false;
                const auto g = parentWidget()->frameGeometry();
                parentWidget()->move(g.x(), g.y() + qAbs(_lastDiff));
            }
            return QLineEdit::event(e);
        }
        

        Hope to clarify it.
        Regards

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 22 Aug 2019, 21:54 last edited by
          #4

          I don't believe X11 will allow negative coordinates, as traditional geometry uses the form

          AxB+C+D where the (+) can also be a (-) to cause the offset to be from the right hand side or bottom of the display.

          You should however be able to use coordinates that are GREATER than the visible desktop.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TianHong
            wrote on 27 Aug 2024, 07:28 last edited by
            #5

            I also encountered this problem, can anyone solve it?

            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