WinchellChung
19th March 2008, 20:19
My client wants something artsy. The application has a screen full of widgets. If the user clicks the "X" go-away button they want the main screen to be over laid with a 85% semi-transparent black, and have an "Are You Sure?" dialog appear.
I have the dialog working just fine, but my black overlay is not working. Probably due to a trivial newbie mistake.
The situation is that the main window contains a single QStacked widget, each page of which contains a complicated QWidget composed of numerous controls. In the main window I have sub-classed closeEvent(). This is the code I'm using to vainly to apply an 85% black:
int theIndex = m_stackedWidget->currentIndex();
QWidget *currentWidget = m_stackedWidget->widget(theIndex);
QWidget *crepuscularWidget = new QWidget(currentWidget);
crepuscularWidget->resize(currentWidget->size());
QPainter painter(crepuscularWidget);
painter.setOpacity(0.85);
painter.fillRect(crepuscularWidget->rect(), QBrush(Qt::black));
crepuscularWidget->repaint();
// then follows the code to put up the "Are You Sure?" modal dialog
Originally this was more compact, I've expanded it to aid debugging (e.g., the first line used to end in = m_stackedWidget->widget(m_stackedWidget->currentIndex()))
It doesn't work.
I've tried initializing crepuscularWidget with the main window, stackedWidget, as well as m_stackedWidget->widget(n). I've tried not using crepuscularWidget at all, instead initializing painter with the main window, stackedWidget, and m_stackedWidget->widget(n). I've used crepuscularWidget->repaint() and crepuscularWidget->update(). Nothing seems to work.
Can anybody see what I am doing wrong?
I have the dialog working just fine, but my black overlay is not working. Probably due to a trivial newbie mistake.
The situation is that the main window contains a single QStacked widget, each page of which contains a complicated QWidget composed of numerous controls. In the main window I have sub-classed closeEvent(). This is the code I'm using to vainly to apply an 85% black:
int theIndex = m_stackedWidget->currentIndex();
QWidget *currentWidget = m_stackedWidget->widget(theIndex);
QWidget *crepuscularWidget = new QWidget(currentWidget);
crepuscularWidget->resize(currentWidget->size());
QPainter painter(crepuscularWidget);
painter.setOpacity(0.85);
painter.fillRect(crepuscularWidget->rect(), QBrush(Qt::black));
crepuscularWidget->repaint();
// then follows the code to put up the "Are You Sure?" modal dialog
Originally this was more compact, I've expanded it to aid debugging (e.g., the first line used to end in = m_stackedWidget->widget(m_stackedWidget->currentIndex()))
It doesn't work.
I've tried initializing crepuscularWidget with the main window, stackedWidget, as well as m_stackedWidget->widget(n). I've tried not using crepuscularWidget at all, instead initializing painter with the main window, stackedWidget, and m_stackedWidget->widget(n). I've used crepuscularWidget->repaint() and crepuscularWidget->update(). Nothing seems to work.
Can anybody see what I am doing wrong?