myClass my;my.show();
QPalette p = this->palette();p.setBrush( this->backgroundRole(), QBrush(QColor(0, 255, 0, 127)) );this->setAutoFillBackground(false);this->setPalette( p );
this->setStyleSheet("background: transparent");this->setCacheMode(QGraphicsView::CacheBackground);QPalette p (this->palette());p.setBrush(QPalette::Window,Qt::transparent);this->setPalette(p);this->setAttribute(Qt::WA_TranslucentBackground);
int main(int argc, char *argv[]){ QApplication app(argc, argv); ShapedClock clock; clock.setAttribute(Qt::WA_TranslucentBackground); clock.setWindowFlags(Qt::FramelessWindowHint); clock.show(); return app.exec();}
#include <QtGui>#include "coloritem.h"#include "robot.h"#include <math.h>int main(int argc, char **argv){ QApplication app(argc, argv); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); QGraphicsScene scene(-200, -200, 400, 400); for (int i = 0; i < 10; ++i) { ColorItem *item = new ColorItem; item->setPos(::sin((i * 6.28) / 10.0) * 150, ::cos((i * 6.28) / 10.0) * 150); scene.addItem(item); } Robot *robot = new Robot; robot->scale(1.2, 1.2); robot->setPos(0, -20); scene.addItem(robot); QPalette palette = app.palette(); palette.setColor( QPalette::Window, Qt::transparent ); palette.setColor( QPalette::Button, Qt::transparent ); palette.setColor( QPalette::Base, Qt::transparent ); palette.setColor( QPalette::Light, Qt::transparent ); palette.setColor( QPalette::Midlight, Qt::transparent ); palette.setColor( QPalette::Dark, Qt::transparent ); palette.setColor( QPalette::Mid, Qt::transparent ); palette.setColor( QPalette::Shadow, Qt::transparent ); QGraphicsView view(&scene); view.setPalette(palette); view.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); view.setAttribute(Qt::WA_TranslucentBackground); view.setRenderHint(QPainter::Antialiasing); view.setWindowTitle("Drag and Drop Robot"); view.show(); return app.exec();}
QGraphicsView view(&scene);
view.setFrameStyle(QFrame::NoFrame);