#include <QApplication>
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QGroupBox>
#include <QFrame>
static void testWidgetRect()
{
root
->setGeometry
(QRect(0,
0,
500,
500));
root->setPalette(palette);
root->setAutoFillBackground(true);
frame
->setGeometry
(QRect(20,
20,
400,
400));
frame->setPalette(palette1);
frame->setAutoFillBackground(true);
groupBox
->setGeometry
(QRect(5,
5,
200,
400 ));
groupBox->setPalette(palette2);
groupBox->setAutoFillBackground(true);
root->setWindowTitle( "testWidgetRect" );
root->show();
}
static void testGraphicsRect()
{
// test graphics
scene->setSceneRect( 0, 0, 500, 500 );
outerRect
->setRect
( QRectF( 20,
20,
400,
400 ) );
outerRect
->setBrush
( QBrush( Qt
::black ) );
innerRect
->setRect
( QRectF( 5,
5,
200,
400 ) );
innerRect->setParentItem( outerRect );
innerRect
->setPen
( QPen( Qt
::red ) );
innerRect
->setBrush
( QBrush( Qt
::red ) );
scene->addItem( outerRect );
view->setWindowTitle( "testGraphicsRect" );
view->show();
}
int main( int argc, char** argv )
{
// test widget
testWidgetRect();
// test graphics
testGraphicsRect();
return app.exec();
}
#include <QApplication>
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QGroupBox>
#include <QFrame>
static void testWidgetRect()
{
QWidget* root = new QWidget;
root->setGeometry(QRect(0, 0, 500, 500));
QPalette palette;
QBrush brush( Qt::white );
palette.setBrush(QPalette::Inactive, QPalette::Window, brush);
palette.setBrush(QPalette::Active, QPalette::Window, brush);
root->setPalette(palette);
root->setAutoFillBackground(true);
QWidget* frame = new QFrame(root);
frame->setGeometry(QRect(20, 20, 400, 400));
QPalette palette1;
QBrush brush1( Qt::black );
palette1.setBrush(QPalette::Inactive, QPalette::Window, brush1);
palette1.setBrush(QPalette::Active, QPalette::Window, brush1);
frame->setPalette(palette1);
frame->setAutoFillBackground(true);
QWidget* groupBox = new QGroupBox(frame);
groupBox->setGeometry(QRect(5, 5, 200, 400 ));
QPalette palette2;
QBrush brush2( Qt::red );
palette2.setBrush(QPalette::Inactive, QPalette::Window, brush2);
palette2.setBrush(QPalette::Active, QPalette::Window, brush2);
groupBox->setPalette(palette2);
groupBox->setAutoFillBackground(true);
root->setWindowTitle( "testWidgetRect" );
root->show();
}
static void testGraphicsRect()
{
// test graphics
QGraphicsScene* scene = new QGraphicsScene;
scene->setSceneRect( 0, 0, 500, 500 );
QGraphicsRectItem* outerRect = new QGraphicsRectItem;
outerRect->setRect( QRectF( 20, 20, 400, 400 ) );
outerRect->setBrush( QBrush( Qt::black ) );
QGraphicsRectItem* innerRect = new QGraphicsRectItem;
innerRect->setRect( QRectF( 5, 5, 200, 400 ) );
innerRect->setParentItem( outerRect );
innerRect->setPen( QPen( Qt::red ) );
innerRect->setBrush( QBrush( Qt::red ) );
scene->addItem( outerRect );
QGraphicsView* view = new QGraphicsView(scene);
view->setWindowTitle( "testGraphicsRect" );
view->show();
}
int main( int argc, char** argv )
{
QApplication app(argc, argv);
// test widget
testWidgetRect();
// test graphics
testGraphicsRect();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks