C++ (Qt) QPixmap px = QPixmap::grabWidget( this ); QPainter p( &px ); p.setBrush( QColor( 0, 0, 0, 100 ) ); // highligh a bit p.setPen( Qt::NoPen ); p.drawRect( px.rect() ); p.end();
C++ (Qt)painter->fillRect(boundingRect(), QColor( 0, 0, 0, 100 ));
C++ (Qt)setEnabled(false);//по желанию qApp->processEvents();dlg.exec();setEnabled(true);
C++ (Qt)painter->setRenderHint(QPainter::Antialiasing);painter->fillRect(boundingRect(), QColor( 0, 0, 0, 100 ));
class Glass : public QDialog{ Q_OBJECTpublic: Glass(QWidget *parent = 0); ~Glass(); QBrush *mask; QLabel *informationText; QLabel *glass; QLabel *animationContainer; QLabel *progress; QMovie *defaultMovie; int install; // 1 - положить стекло 0 - убрать void installGlass(QWidget *w);public slots: void removeGlass(); void setProgress(double p);};Glass::Glass(QWidget *parent): QDialog(parent){ install = 0; QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect(parent); const QColor& color = QColor(111, 111, 100); mask = new QBrush(); mask->setColor(color); mask->setStyle(Qt::SolidPattern); qreal opacity = 0.7; opacityEffect->setOpacityMask(*mask); opacityEffect->setOpacity(opacity); glass = new QLabel(parent); glass->setGraphicsEffect(opacityEffect); glass->setVisible(false); informationText = new QLabel(parent); informationText->setVisible(false); informationText->setText(trUtf8("Подождите\n Выполняется отбор данных...")); QFont font; font.setPointSize(12); font.setWeight(QFont::Bold); informationText->setFont(font); informationText->setAlignment(Qt::AlignHCenter); QPalette pal(informationText->palette()); pal.setColor(QPalette::Foreground, QColor("white")); informationText->setPalette(pal); animationContainer = new QLabel(parent); animationContainer->setVisible(false); defaultMovie = new QMovie("/pictures/loading51.gif", QByteArray(), animationContainer); animationContainer->setMovie(defaultMovie); defaultMovie->start(); progress = new QLabel(parent); progress->setVisible(false); progress->setPalette(pal); progress->setAlignment(Qt::AlignHCenter);}Glass::~Glass(){ delete progress; delete defaultMovie; delete animationContainer; delete informationText; delete glass; delete mask;}void Glass::installGlass(QWidget *w){ install = 1; glass->setVisible(true); informationText->setVisible(true); animationContainer->setVisible(true); progress->setVisible(true); progress->setGeometry(w->size().width()/2 - 17,w->size().height()/2 - 80,30,15); animationContainer->setGeometry(w->size().width()/2 - 65,w->size().height()/2 - 150,300,150); informationText->setGeometry(w->size().width()/2 - 150,w->size().height()/2,300,150); glass->setGeometry(0,0,w->size().width(),w->size().height());}void Glass::removeGlass(){ install = 0; glass->setVisible(false); informationText->setVisible(false); animationContainer->setVisible(false); progress->setVisible(false);}void Glass::setProgress(double p){ QString str_persent; str_persent.setNum((int)p); progress->setText(str_persent);}