Results 1 to 3 of 3

Thread: How to display a widget on top of other widgets in the same window

  1. #1
    Join Date
    Oct 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to display a widget on top of other widgets in the same window

    Hi there,
    I have widget containing a layout. Sometimes I need to display another widget.
    And I would like to do it on top of that layout. As well I would like to have a semi-transparent background of top widget.
    To make things more clear I give you a photoshopped example:

    How can I do it with Qt?
    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to display a widget on top of other widgets in the same window

    Don't set a parent.

  3. #3
    Join Date
    Oct 2010
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to display a widget on top of other widgets in the same window

    I've managed to solve that problem:
    Qt Code:
    1. MainWidget::MainWidget(QObject* parent)
    2. {
    3. mainLayout = new QVBoxLayout;
    4. mainLayout->addWidget(widget1);
    5. mainLayout->addWidget(widget2);
    6. mainLayout->addWidget(widget3);
    7. setLayout(mainLayout);
    8. }
    9.  
    10.  
    11. void MainWidget::addInFront()
    12. {
    13. if (mainLayout)
    14. delete mainLayout;
    15. newWidget = new NewWidget(this);
    16. mainLayout = new QVBoxLayout;
    17. mainLayout->addWidget(newWidget);
    18. setLayout(mainLayout);
    19. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. NewWidget::NewWidget(QObject* parent)
    2. {
    3. setAutoFillBackground(true);
    4. //setAttribute(Qt::WA_OpaquePaintEvent);
    5. QPalette palette = this->palette();
    6. palette.setColor(QPalette::Window, QColor(255,255,255,192));
    7. this->setPalette(palette);
    8.  
    9. newLayout = new QVBoxLayout;
    10. newLayout->addWidget(widget0);
    11. setLayout(newLayout);
    12. }
    To copy to clipboard, switch view to plain text mode 
    That code does everything what I want.
    As for placing widgets in front of parent's I've found two useful links:

    But now I have to new questions:
    • As for Qt::WA_OpaquePaintEvent, am I right that I need that attribute only when re-implement paintEvent and want to draw background by myself?
    • And the big one for me. When I follow the described tactic it works only when the margin is -20, otherwise there is some space not covered with the background of NewWidget.

      The widget and it's background are pink. How can I resize it to fill the whole window?
    Last edited by Cucumber; 2nd November 2010 at 17:09.

Similar Threads

  1. QLogText & QLogTable : 2 widgets to display text log
    By fcoiffie in forum Qt-based Software
    Replies: 7
    Last Post: 28th April 2019, 08:52
  2. Replies: 2
    Last Post: 20th August 2010, 14:20
  3. Replies: 5
    Last Post: 19th April 2010, 00:31
  4. Replies: 0
    Last Post: 1st October 2008, 17:21
  5. Replies: 6
    Last Post: 3rd January 2008, 10:33

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.