Dear All,

I am working on an application where in which I need to determine the state of the window based on the visibility state.
I have an enum declared as follows:
enum APP_WIN_STATE
{
APP_WIN_INACTIVE, // Window in not associated with a display
APP_WIN_OBSCURED, // Window is completed obscured on a display
APP_WIN_PARTIAL, // Window is partially obscured on a display
APP_WIN_VISIBLE, // Window is completely visible on a display
};

I need to set the window state based on their visibility states.

Qt Code:
  1. #include <QApplication>
  2. #include <QPalette>
  3. #include <QWidget>
  4. #include <QDebug>
  5. #include <QString>
  6.  
  7. void printWidgetProperties(QWidget *pWidget, QString message)
  8. {
  9. qDebug() << message;
  10.  
  11. QRegion visRegn = pWidget->visibleRegion();
  12. if (visRegn.isEmpty())
  13. {
  14. qDebug() << "is *not* visible";
  15. }
  16. else
  17. {
  18. if(visRegn.boundingRect() == pWidget->rect()) {
  19. qDebug() << "is fully visible";
  20. } else {
  21. qDebug() << "is partially visible";
  22. }
  23. }
  24. }
  25.  
  26. QWidget* createWidget(int top, int left, int width, int height, QColor color, QWidget *pParent = NULL)
  27. {
  28. QWidget *pWidget = new QWidget(pParent);
  29. pWidget->setFixedSize(width, height);
  30. pWidget->setGeometry(top, left, width, height);
  31.  
  32. QPalette pal;
  33. pal.setColor(QPalette::Background, color);
  34. pWidget->setAutoFillBackground(true);
  35. pWidget->setPalette(pal);
  36.  
  37. return pWidget;
  38. }
  39.  
  40. int main(int argc, char *argv[ ])
  41. {
  42. QApplication app(argc, argv);
  43.  
  44. QPalette pal;
  45. QWidget *pMainWin = createWidget(0, 0, 480, 272, Qt::white);
  46.  
  47. // QWidget * pWinG = createWidget(10, 10, 420, 260, Qt::green, pMainWin);
  48. QWidget * pWinG = createWidget(0, 0, 480, 272, Qt::green, pMainWin);
  49.  
  50. // QWidget * pWinB = createWidget(190, 86, 100, 100, Qt::blue, pMainWin);
  51. QWidget * pWinB = createWidget(0, 0, 480, 20, Qt::blue, pMainWin);
  52.  
  53. // QWidget * pWinR = createWidget(380, 86, 70, 50, Qt::red, pMainWin);
  54. QWidget * pWinR = createWidget(0, 20, 480, 252, Qt::red, pMainWin);
  55.  
  56. QWidget * pWinY = createWidget(380, 86, 70, 50, Qt::yellow, pMainWin);
  57.  
  58. pMainWin->show();
  59.  
  60. printWidgetProperties(pWinG, "Widget Green");
  61. printWidgetProperties(pWinR, "Widget Red");
  62. printWidgetProperties(pWinB, "Widget Blue");
  63. printWidgetProperties(pWinY, "Widget Yellow");
  64.  
  65. return app.exec();
  66. }
To copy to clipboard, switch view to plain text mode 

In the above code I am trying to determine each widget state based on the visibility region. My expectations are as follows from the code:
a. Widget Green - Completely Obscured
b. Widget Blue - Cimpletely Visible
c. Widget Red - Partially Visiblle
d. Widget Yellow - Completely Visible

But the above code gives me an output that
"Widget Green"
is *not* visible
"Widget Red"
is fully visible
"Widget Blue"
is fully visible
"Widget Yellow"
is fully visible

Query: How do we determine that widget is partially visible (in my case yellow widget is enclosing some part of the Red Widget and hence Red Widget is partially visible)?
Is there a way to say that a Widget (Red Widget in my example) is partially Visible in Qt?
Kindly do the needful

Regards
SRaju