Results 1 to 5 of 5

Thread: QWidget over current widget - it's in place, but not painted

  1. #1
    Join Date
    Sep 2009
    Location
    Poland, Cracow
    Posts
    34
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QWidget over current widget - it's in place, but not painted

    Hi,

    I just created simple "QMainWindow" application, just from QtCreator New Project wizard. I've added two push buttons into center widget, then each of them connected (clicked() signal) with slots:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. w = new QWidget(this);
    4. w->move(0, 0);
    5. w->setFixedSize(50, 200);
    6. w->setVisible(true);
    7. }
    8.  
    9. void MainWindow::on_pushButton_2_clicked()
    10. {
    11. delete w;
    12. }
    To copy to clipboard, switch view to plain text mode 

    What bothers me is that after pressing button1, widget is created and resized as expected, but it's not painted at all. I mean I see that the widget is there, because it covers left part of the upper push button, therefore the pushbutton doesn't light-up on mouse over event, but when I move mouse right the pushbutton lights up. But... the widget itself is not painted at all, like it was transparent

    What am I missing here? Shouldn't the widget paint itself as empty rectangle, instead of transparent one?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QWidget over current widget - it's in place, but not painted

    What am I missing here? Shouldn't the widget paint itself as empty rectangle, instead of transparent one?
    A QWidget by default has nothing to paint, it just empty. This is expected behavior.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Sep 2009
    Location
    Poland, Cracow
    Posts
    34
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget over current widget - it's in place, but not painted

    I see. What about QFrame? I tried with that too, with same result.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QWidget over current widget - it's in place, but not painted

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. w = new QFrame(this); //<<<<<<<<<<<<< change w to QFrame *
    4. w->move(0, 0);
    5. w->setFixedSize(50, 200);
    6. w->setVisible(true);
    7. w->setFrameStyle(QFrame::Box); //<<<<<<<<<<<<<< this is required
    8. }
    9.  
    10. void MainWindow::on_pushButton_2_clicked()
    11. {
    12. delete w;
    13. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    googie (19th June 2013)

  6. #5
    Join Date
    Sep 2009
    Location
    Poland, Cracow
    Posts
    34
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget over current widget - it's in place, but not painted

    Found it! QWidget::setAutoFillBackground(true) was the key.
    Last edited by googie; 19th June 2013 at 11:13.

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 18:42
  2. How to erase everything widget has painted?
    By TheNewGuy in forum Newbie
    Replies: 1
    Last Post: 12th December 2009, 07:23
  3. Replies: 0
    Last Post: 3rd March 2009, 15:38
  4. Widget not painted properly
    By qwakaw in forum Qt Programming
    Replies: 0
    Last Post: 11th November 2008, 11:30
  5. Replies: 5
    Last Post: 29th August 2007, 16:36

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.