I can create and see a QWidget in one of the functions of main window class:
..
// ok
QWidget *w = new QWidget(this);
w->setGeometry(400,300,400,300);
w->setStyleSheet("background-color:white;");
w->show();
..
but when I try to do something similar by creating another class which is derived from QWidget, I can't see anything:
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *sParent):QWidget(sParent)
{
}
};
..
// nothing visible happens.
MyWidget *w = new MyWidget(this);
w->setGeometry(400,300,400,300);
w->setStyleSheet("background-color:white;");
w->show();
..
what may cause this?
Note: Everything about this question: http://pastebin.com/haCHfqnu
You can rewrite the paintEvent.
void MyWidget::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
I think that will fix the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With