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. Force dialogs to float; like QInputDialog
Forum Updated to NodeBB v4.3 + New Features

Force dialogs to float; like QInputDialog

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 479 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.
  • S Offline
    S Offline
    swurl
    wrote on last edited by
    #1

    Pretext: I use a tiling window manager that has the ability to make certain windows float (in my case, sway).

    Whenever I use Qt's built-in dialogs like QInputDialog, the dialogs float as such (using QInputDialog::getText):

    cd2350be-2d26-4a1a-8ec6-abcb9e2599ed-image.png

    However, I am looking to getting QDialogs I subclass to also show like this, but all of them get tiled along with the rest of my windows.

    I looked at the source code for the getText method:

    QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label,
                                  QLineEdit::EchoMode mode, const QString &text, bool *ok,
                                  Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
    {
        QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
        dialog->setWindowTitle(title);
        dialog->setLabelText(label);
        dialog->setTextValue(text);
        dialog->setTextEchoMode(mode);
        dialog->setInputMethodHints(inputMethodHints);
    
        const int ret = dialog->exec();
    // ...
    }
    

    This looks suspiciously like it does absolutely nothing to make it appear as a popup like that, except maybe for the use of exec. I tried using exec as well (which I wouldn't have wanted either way due to its blocking nature), but this did NOT work.

    I also tried various window flags; Qt::WindowStaysOnTopHint, Qt::Popup, Qt::Tool, none achieved anything. Tried setModal(true), didn't work.

    What does the QInputDialog do to achieve this that I don't understand? Or is this some weird quirk of i3/sway?

    C 1 Reply Last reply
    0
    • S swurl

      @ChrisW67 The QInputDialog's parent widget is the main window class. Looks like I forgot to set the parent of the other dialogs... would that achieve the behavior I'm looking for?

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #4

      @swurl The window manager may treat a top-level modal dialog, i.e. unparented and opened with exec(), to one that has a parent. It may also treat an application modal dialog differently to a window-modal one.

      S 1 Reply Last reply
      1
      • S swurl

        Pretext: I use a tiling window manager that has the ability to make certain windows float (in my case, sway).

        Whenever I use Qt's built-in dialogs like QInputDialog, the dialogs float as such (using QInputDialog::getText):

        cd2350be-2d26-4a1a-8ec6-abcb9e2599ed-image.png

        However, I am looking to getting QDialogs I subclass to also show like this, but all of them get tiled along with the rest of my windows.

        I looked at the source code for the getText method:

        QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label,
                                      QLineEdit::EchoMode mode, const QString &text, bool *ok,
                                      Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
        {
            QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
            dialog->setWindowTitle(title);
            dialog->setLabelText(label);
            dialog->setTextValue(text);
            dialog->setTextEchoMode(mode);
            dialog->setInputMethodHints(inputMethodHints);
        
            const int ret = dialog->exec();
        // ...
        }
        

        This looks suspiciously like it does absolutely nothing to make it appear as a popup like that, except maybe for the use of exec. I tried using exec as well (which I wouldn't have wanted either way due to its blocking nature), but this did NOT work.

        I also tried various window flags; Qt::WindowStaysOnTopHint, Qt::Popup, Qt::Tool, none achieved anything. Tried setModal(true), didn't work.

        What does the QInputDialog do to achieve this that I don't understand? Or is this some weird quirk of i3/sway?

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #2

        @swurl What is the parent widget of the QInputDialog? And yours?

        S 1 Reply Last reply
        0
        • C ChrisW67

          @swurl What is the parent widget of the QInputDialog? And yours?

          S Offline
          S Offline
          swurl
          wrote on last edited by
          #3

          @ChrisW67 The QInputDialog's parent widget is the main window class. Looks like I forgot to set the parent of the other dialogs... would that achieve the behavior I'm looking for?

          C 1 Reply Last reply
          0
          • S swurl

            @ChrisW67 The QInputDialog's parent widget is the main window class. Looks like I forgot to set the parent of the other dialogs... would that achieve the behavior I'm looking for?

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #4

            @swurl The window manager may treat a top-level modal dialog, i.e. unparented and opened with exec(), to one that has a parent. It may also treat an application modal dialog differently to a window-modal one.

            S 1 Reply Last reply
            1
            • C ChrisW67

              @swurl The window manager may treat a top-level modal dialog, i.e. unparented and opened with exec(), to one that has a parent. It may also treat an application modal dialog differently to a window-modal one.

              S Offline
              S Offline
              swurl
              wrote on last edited by
              #5

              @ChrisW67 Thanks, it appears that having no parent widget treated it as a top-level independent window, but adding the parent widget worked, even without exec(). Thanks!

              1 Reply Last reply
              1
              • S swurl has marked this topic as solved on

              • Login

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