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. Window always on top but don't block input from others

Window always on top but don't block input from others

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.9k 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    i want to have a window that stays always on top of my MainWindow, but it shouldn't block the input from it.
    OpenFileDialogs shouldn't be affected. So if i have my subwindow open, it stays over my MainWindow, but not over the FileOpenDialog.

    i tried Qt::WindowStaysOnTopHint, but this makes it stay always on top and not only in top of my MainWindow.

    using WindowModal and ApplicationModal both block the interaction with MainWindow.

    I hope someone can help me :D

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      You're overcomplicating it. Just make the window child of the main window:

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          MainWindow w;
          w.show();
      
          QDialog* dialog = new QDialog(&w);
          dialog->show();
      
          QFileDialog::getExistingDirectory(&w, "Hello");
      
          return a.exec();
      }
      

      or, if you want to use a plain QWidget instead of QDialog:

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          MainWindow w;
          w.show();
      
          QWidget* widget = new QWidget(&w, Qt::Window);
          widget->show();
      
          QFileDialog::getExistingDirectory(&w, "Hello");
      
          return a.exec();
      }
      
      1 Reply Last reply
      2
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by
        #3

        @Chris-Kawa sometimes the easy way is the best way :D

        Just one question i changed the palette from the QScrollArea of my subwindow, so the background is painted white.
        Now it doesn't work anymore. I don't know why. Any ideas??

        Already tried this:

        ui->scrollArea->setStyleSheet("QScrollArea{background-color: #ffffff}");
        

        But does not work.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Oh it works. It's just covered by other widgets. Inside a scroll area there's a viewport widget and in it a contents widget.
          You can do what you want in many ways. For example you can narrow your stylesheet to apply to two widgets down:

          ui->scrollArea->setStyleSheet("QScrollArea>QWidget>QWidget {background-color: #ffffff}");
          

          Unfortunately that will also color the scrollbars, but you can instead style the content directly:

          ui->scrollArea->widget()->setStyleSheet("background-color: #ffffff");
          

          or be even more specific by giving it a name:

          ui->scrollArea->widget()->setObjectName("content");
          ui->scrollArea->setStyleSheet("#content {background-color: #ffffff}");
          

          Yet another alternative, if you really want to color the scrollarea itself, is to stop Qt from drawing the background of the content:

          ui->scrollArea->setStyleSheet("QScrollArea{background-color: #ffffff}");
          ui->scrollArea->widget()->setAutoFillBackground(false);
          

          Btw. Changing palette colors is wobbly at best. Not all styles use the palette for all elements.

          1 Reply Last reply
          3

          • Login

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