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:
Code:
void MainWindow::on_pushButton_clicked()
{
w->move(0, 0);
w->setFixedSize(50, 200);
w->setVisible(true);
}
void MainWindow::on_pushButton_2_clicked()
{
delete w;
}
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?
Re: QWidget over current widget - it's in place, but not painted
Quote:
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.
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.
Re: QWidget over current widget - it's in place, but not painted
Code:
void MainWindow::on_pushButton_clicked()
{
w
= new QFrame(this);
//<<<<<<<<<<<<< change w to QFrame * w->move(0, 0);
w->setFixedSize(50, 200);
w->setVisible(true);
w
->setFrameStyle
(QFrame::Box);
//<<<<<<<<<<<<<< this is required}
void MainWindow::on_pushButton_2_clicked()
{
delete w;
}
Re: QWidget over current widget - it's in place, but not painted
Found it! QWidget::setAutoFillBackground(true) was the key.