15

How can I make a Qt dialog window always on top at my application level?

I want to make a dialog window always on the front but remember always on the front at my application level, even if I click on an empty place, I want to it stay on the front of my application only.

I have tried to use setWindowFlags(Qt::WindowStaysOnTopHint), but this makes the dialog window always on the top at the desktop level, but I want it to be on top at the my application level only.

How can I do that?

Lion King
  • 32,851
  • 25
  • 81
  • 143
  • Try to set Qt::Dialog or Qt::Window flag to your dialog (with setWindowsFlags method) – Jablonski Oct 11 '14 at 15:08
  • 1
    @Chernobyl: I have used `setWindowFlags(Qt::Tool)` with the dialog window. – Lion King Oct 11 '14 at 15:15
  • 1
    Then you should setParent to this window. From doc:Indicates that the widget is a tool window. A tool window is often a small window with a smaller than usual title bar and decoration, typically used for collections of tool buttons. If there is a parent, the tool window will always be kept on top of it. If there isn't a parent, you may consider using Qt::WindowStaysOnTopHint as well. – Jablonski Oct 11 '14 at 15:24
  • 1
    @Chernobyl: your words correct, set the parent is the problem (`+1` for your comment). thank you – Lion King Oct 11 '14 at 15:30

2 Answers2

13

You can achieve this by giving the dialogs a parent. A child dialog always stays on top of its parent window.

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
4

If you can't send parent to your dialog_window (based on code conditional) Like me, use flags.

Dialog_dlg::Dialog_dlg(QWidget *parent)
    : QDialog(parent), ui(new Ui::Dialog_dlg)
{
    ui->setupUi(this);
    setFixedSize(width(), height()); //for no maximaize
    setWindowFlag(Qt::WindowStaysOnTopHint);
}

I used this and good to me. See other flags, test them, and choose.

Mahdi
  • 87
  • 5