Important: Please read the Qt Code of Conduct -

QDialog added to QGraphicsScene has no titlebar

  • I'm trying to achieve the effect shown in the first image on this page: . However, my QDialog is not displaying its titlebar. Here is my relevant code:

    void MainWindow(this is a QGraphicsView)::loginScreen()
    QDialog* login = new QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    login->setWindowTitle("Connect to");
    login->setLayout(new VBoxLayout);
    login->layout()->addWidget(new QLineEdit("###.###.###.###"));
    login->layout()->addWidget(new QPushButton("Ok"));
    QGraphicsProxyWidget* proxy = scene()->addWidget(login);
    proxy->resize(size().width()/3, proxy->preferredSize().height());
    proxy->setPos(size().width()/2-proxy->size().width()/2, size().height()/2-proxy->size().height()/2);

    Everything else displays fine, I just can't get the dialog's titlebar to show, nor can I move the dialog around. If it's not possible to fix the titlebar, I'd like to at least make the dialog movable.

  • The title and the moving part are things that are drawn by the window manager, which is part of your operating system. Not Qt. Which explains why you don't see them.

    But please go through the examples and demos there are some in there that do very similar stuff, and the source is right there :)

  • On your line:
    QGraphicsProxyWidget* proxy = scene()->addWidget(login);

    Change it to:

    QGraphicsProxyWidget* proxy = scene()->addWidget(login,Qt::Window);

    It will then draw it as a mini window with the proper decorations.

  • That worked perfectly, thank you

Log in to reply