Results 1 to 7 of 7

Thread: How to make frameless widget as a window or dialog

  1. #1

    Default How to make frameless widget as a window or dialog

    I made a frameless widget which has its own titlebar. When this widget has a parent widget, it doesn't act as a separate window anymore, but I want to have it popup as a dialog. Unfortunately I can't minimize, maximize it. It stays inside the parent widget frame. How can I make this frameless widget still act as an independent window or dialog when it has a parent widget?

    The code looks something like this:

    #include <QtGui>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QMainWindow mainWin;
    mainWin.show();

    FramelessWidget myWid(&mainWin, Qt:ialog | Qt::FramelessWindowHint);
    myWid.show();

    return app.exec();
    }

    Anyone has any ideas?
    Last edited by ainne810329; 3rd November 2011 at 12:32.

  2. #2
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make frameless widget as a window or dialog

    Hi

    ok first of all, what kind of widget is your FramelessWidget? QWidget? QDialog? QObject?
    when its from QDialog, then u dont need to set a parent in your constructor:
    Qt Code:
    1. main.cpp:
    2. ...
    3. FramelessWidget myWid(Qt::Dialog | Qt::FramelessWindowHint);
    4. myWid.show();
    To copy to clipboard, switch view to plain text mode 
    but then u have to change your constructor in your framelesswidget.cpp to:
    Qt Code:
    1. FramelessWidget(..., QWidget* parent = 0);
    To copy to clipboard, switch view to plain text mode 
    because arguments with default-values must be at last positions in the constructor.

    if your FramelessWidget is inhertide from QWidegt, then u need a QDialog or QMainWindow like:

    Qt Code:
    1. main.cpp:
    2. {
    3. ...
    4. QMainWindow mainWin;
    5. mainWin.show();
    6.  
    7. QDialog dia;
    8. FramelessWidget(&dia, Qt::Dialog | Qt::FramelessWindowHint);
    9. dia.show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    this code snippet creates one MainWindow and one Dialog-Window.

    i hope i could help you

    with best regards

    nudels

  3. #3

    Default Re: How to make frameless widget as a window or dialog

    First, thank you very much for your respond.

    The FramelessWidget is derived from QWidget indeed, by using a QDialog as a parent of my frameless widget, the purpose to have custome title bar and borderless dialog can not be achieved anymore.

    Secondary, I do want this frameless widget to be a child dialog of the mainwindow, so it stays on top of the mainwindow and when the mainwindow is minimized, the frameless dialog is also minimized.

    Any idea how I can achieve my goals?

  4. #4
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make frameless widget as a window or dialog

    can u plz post the framelesswidget constructor?

    u want to have one Window, that is the parent of ur framelesswidget? is that right?

    best regards

    nudels

  5. #5

    Default Re: How to make frameless widget as a window or dialog

    What I really want is a frameless dialog which has a parent window and the frameless widget itself still can act as an independent window although it has a parent.

    Here is the code of the frameless widget:

    class FramelessWidget : public QWidget
    {
    FramelessWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f)
    {
    QVBoxLayout *layout = new QVBoxLayout();
    setLayout(layout);

    TitleBar *titleBar = new TitleBar(this);
    layout->addWidget(titleBar);
    ......
    }
    ......
    }


    Added after 4 minutes:


    Saying it in other words, the FramelessWidget can be created as window, dialog or whatever other widget type as a normal QWidget does. The only difference is the widget has custom titlebar and no window border even when it is a window or dialog.

    It works fine as I want when it doesn't have a parent widget. But when there is a parent widget, this FramelessWidget can not act as an independent window or dialog anymore. It acts more like frame inside the parent widget.
    Last edited by ainne810329; 3rd November 2011 at 13:51.

  6. #6

    Default Re: How to make frameless widget as a window or dialog

    You can combine window flags Qt::Tool and Qt::FramelessWindowHint to achieve this effect.

  7. #7

    Default Re: How to make frameless widget as a window or dialog

    combine Qt:Tool and Qt::FramelessWindowHint doesn't work as I expected. It works exactly the same as combining Qt:ialog and Qt::FramelessWindowHint.

    the frameless window which has a parent can't be minimized or maximized as a normal window, it stays inside the central widget of the parent window.


    Added after 8 minutes:


    Sorry!!!

    I try to set the frameless window with no parent, then combination of Qt::Tool and Qt::FramelessWindowHint works. But it has other problems. Now this frameless window has an entry on the task bar, it can't minimized. Normally, a child dialog won't have entry on the task bar.

    Any ideas to solve the task bar problem???
    Last edited by ainne810329; 4th November 2011 at 11:51.

Similar Threads

  1. Move Frameless Dialog
    By deepal_de in forum Qt Programming
    Replies: 7
    Last Post: 6th June 2011, 09:35
  2. Frameless Window Helper
    By nish in forum Qt-based Software
    Replies: 6
    Last Post: 20th February 2011, 08:28
  3. Replies: 10
    Last Post: 26th October 2010, 00:59
  4. Resize handling of frameless window
    By Peppy in forum Qt Programming
    Replies: 5
    Last Post: 2nd June 2010, 21:48
  5. How to show a frameless dialog - DOESN'T WORK
    By franco.amato in forum Newbie
    Replies: 4
    Last Post: 2nd June 2010, 18:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.