#include <QApplication>
#include <QPalette>
#include <QWidget>
#include <QDebug>
#include <QString>
{
qDebug() << message;
QRegion visRegn
= pWidget
->visibleRegion
();
if (visRegn.isEmpty())
{
qDebug() << "is *not* visible";
}
else
{
if(visRegn.boundingRect() == pWidget->rect()) {
qDebug() << "is fully visible";
} else {
qDebug() << "is partially visible";
}
}
}
QWidget* createWidget
(int top,
int left,
int width,
int height,
QColor color,
QWidget *pParent
= NULL) {
pWidget->setFixedSize(width, height);
pWidget->setGeometry(top, left, width, height);
pal.
setColor(QPalette::Background, color
);
pWidget->setAutoFillBackground(true);
pWidget->setPalette(pal);
return pWidget;
}
int main(int argc, char *argv[ ])
{
QWidget *pMainWin
= createWidget
(0,
0,
480,
272, Qt
::white);
// QWidget * pWinG = createWidget(10, 10, 420, 260, Qt::green, pMainWin);
QWidget * pWinG
= createWidget
(0,
0,
480,
272, Qt
::green, pMainWin
);
// QWidget * pWinB = createWidget(190, 86, 100, 100, Qt::blue, pMainWin);
QWidget * pWinB
= createWidget
(0,
0,
480,
20, Qt
::blue, pMainWin
);
// QWidget * pWinR = createWidget(380, 86, 70, 50, Qt::red, pMainWin);
QWidget * pWinR
= createWidget
(0,
20,
480,
252, Qt
::red, pMainWin
);
QWidget * pWinY
= createWidget
(380,
86,
70,
50, Qt
::yellow, pMainWin
);
pMainWin->show();
printWidgetProperties(pWinG, "Widget Green");
printWidgetProperties(pWinR, "Widget Red");
printWidgetProperties(pWinB, "Widget Blue");
printWidgetProperties(pWinY, "Widget Yellow");
return app.exec();
}
#include <QApplication>
#include <QPalette>
#include <QWidget>
#include <QDebug>
#include <QString>
void printWidgetProperties(QWidget *pWidget, QString message)
{
qDebug() << message;
QRegion visRegn = pWidget->visibleRegion();
if (visRegn.isEmpty())
{
qDebug() << "is *not* visible";
}
else
{
if(visRegn.boundingRect() == pWidget->rect()) {
qDebug() << "is fully visible";
} else {
qDebug() << "is partially visible";
}
}
}
QWidget* createWidget(int top, int left, int width, int height, QColor color, QWidget *pParent = NULL)
{
QWidget *pWidget = new QWidget(pParent);
pWidget->setFixedSize(width, height);
pWidget->setGeometry(top, left, width, height);
QPalette pal;
pal.setColor(QPalette::Background, color);
pWidget->setAutoFillBackground(true);
pWidget->setPalette(pal);
return pWidget;
}
int main(int argc, char *argv[ ])
{
QApplication app(argc, argv);
QPalette pal;
QWidget *pMainWin = createWidget(0, 0, 480, 272, Qt::white);
// QWidget * pWinG = createWidget(10, 10, 420, 260, Qt::green, pMainWin);
QWidget * pWinG = createWidget(0, 0, 480, 272, Qt::green, pMainWin);
// QWidget * pWinB = createWidget(190, 86, 100, 100, Qt::blue, pMainWin);
QWidget * pWinB = createWidget(0, 0, 480, 20, Qt::blue, pMainWin);
// QWidget * pWinR = createWidget(380, 86, 70, 50, Qt::red, pMainWin);
QWidget * pWinR = createWidget(0, 20, 480, 252, Qt::red, pMainWin);
QWidget * pWinY = createWidget(380, 86, 70, 50, Qt::yellow, pMainWin);
pMainWin->show();
printWidgetProperties(pWinG, "Widget Green");
printWidgetProperties(pWinR, "Widget Red");
printWidgetProperties(pWinB, "Widget Blue");
printWidgetProperties(pWinY, "Widget Yellow");
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks