本文整理汇总了C++中QPixmap::grabWidget方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::grabWidget方法的具体用法?C++ QPixmap::grabWidget怎么用?C++ QPixmap::grabWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPixmap
的用法示例。
在下文中一共展示了QPixmap::grabWidget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mousePressEvent
void DragLabel::mousePressEvent(QMouseEvent * e)
{
QString str = text();
QPixmap pix;
pix = pix.grabWidget(this);
QByteArray data;
QDataStream stream(&data,QIODevice::WriteOnly);
stream << str << QPoint(e->pos()-rect().topLeft());
QMimeData *mimeData = new QMimeData;
mimeData->setData("Drag-Text",data);
mimeData->setText(str);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(QPoint(e->pos() - rect().topLeft()));
drag->setPixmap(pix);
hide();
Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
if (dropAction == Qt::MoveAction)
close();
else
show();
}
示例2: paintEvent
void DatePicker::paintEvent(QPaintEvent *e)
{
if (parentWidget() && parentWidget()->backgroundRole()){
QPoint pos = mapToParent(QPoint(0, 0));
QPainter p(this);
QPixmap pimage;
p.drawTiledPixmap(0, 0, width(), height(), pimage.grabWidget( parentWidget(), 0,0, height(), width()), pos.x(), pos.y());
return;
}
QFrame::paintEvent(e);
}
示例3: plotPic
void Widget::plotPic(QPrinter *printer)
{
QDialog *myForm = myprinter;
QPainter painter(printer);
QPixmap image;
image=image.grabWidget(myForm,0,0,400,300); /* 绘制窗口至画布 */
QRect rect = painter.viewport();
QSize size = image.size();
size.scale(rect.size(), Qt::KeepAspectRatio); //此处保证图片显示完整
painter.setViewport(rect.x(), rect.y(),size.width(), size.height());
painter.setWindow(image.rect());
painter.drawPixmap(0,0,image); /* 数据显示至预览界面 */
}
示例4: print
void PharmacyReceipt::print( QPrinter* printer )
{
//// 创建打印页面的绘制对象
QPainter painter( printer );
int w = printer->pageRect().width();
int h = printer->pageRect().height();
QRect page( w/5, h/15, w, h );
QRect page2( w/4, h/8, w, h );
QRect page3( w/4, h/6, w, h );
QRect page4( 0, h/10, w, h );
// 根据页面大小设置适当的字体大小
QFont font = painter.font();
font.setPixelSize( (w+h) / 100 );
painter.setFont( font );
// 在页面角落绘制标签
painter.drawText( page, Qt::AlignTop | Qt::AlignLeft, QString::fromLocal8Bit(" 三河市燕郊镇卫生院") );
/*painter.drawText( page2, Qt::AlignTop | Qt::AlignLeft, QString::fromLocal8Bit("周文军") );
painter.drawText( page3, Qt::AlignTop | Qt::AlignLeft, QString::fromLocal8Bit("一般针疗费 次 1 10.00") );
painter.drawText( page4, Qt::AlignTop | Qt::AlignLeft, QString::fromLocal8Bit("六十九元九角整"));
painter.drawText( page, Qt::AlignBottom | Qt::AlignLeft,
QDateTime::currentDateTime().toString( Qt::DefaultLocaleShortDate ) );*/
// 绘制模拟数据
page.adjust( w/20, h/20, -w/20, -h/20 );
//m_scene->render( &painter, page );
//表格
/* QWidget *myForm=new QWidget(this);
myForm->setObjectName(QString::fromUtf8("Form"));
myForm->resize(500, 500);
QTableWidget *tableWidget;
tableWidget = new QTableWidget(myForm);
tableWidget->setColumnCount(3);
tableWidget->setRowCount(4);
tableWidget->setObjectName(QString::fromUtf8("tableWidget"));
tableWidget->setGeometry(QRect(0, 0,500, 500));
tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color:white;color: black;padding-left: 4px;border: 1px solid #6c6c6c;};"
"color: white;padding-left: 4px;border: 1px solid #6c6c6c;}"
"QHeaderView::section:checked{background-color: red;}"); */
QPixmap image;
image=image.grabWidget(ui.tableWidget,-35,0,900, 1000);
painter.drawPixmap(page4,image);
//printTableWidget(ui.tableWidget,"preview",printer);
}
示例5: on_capture_pushButton_clicked
/*
* 抓取屏幕
*/
void MainWindow::on_capture_pushButton_clicked()
{
QString fileName;
QPixmap pixmap;
QPixmap pix;
//this->width ()
//pix = pixmap.grabWidget (this,680,130,300,540); // 獲取當前窗口 (0 , 0, -1, -1)
//获取抓取的横纵坐标
//int grapX= year_lineEdit->geometry ().x ();
//int grapY = year_lineEdit->geometry ().y ();
//使用grabWidget 获取截图 gridLayout_2
pix = pixmap.grabWidget (this->frame_capture, 0 ,0, this->frame_capture->width (), this->frame_capture->height () );
//pix = pixmap.grabWindow(QApplication::desktop()->winId()); // 獲取整個屏幕窗口
// 當前時間命名
//fileName = "/"+QDateTime::currentDateTime().toString("yyyy-mm-dd hh-mm-ss") + ".PNG";
//保存文件
if (pix.isNull())
{
QMessageBox::information(this, "error", "grab Screen failed!", QMessageBox::Ok);
}
else
{
//QString path = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
QString fileName = QFileDialog::getSaveFileName(this,
tr("快照"),
"",
tr("图片(*.PNG)"));
if(fileName!="")
{
//fileName = path+"/指数截图.png";
if (!pix.save(fileName, "PNG"))
{
QMessageBox::information(this, "right", "保存失败!", QMessageBox::Ok);
}
else
{
QMessageBox::information(this, "Grab", "保存成功!", QMessageBox::Ok);
}
}
}
}
示例6: on_captureIntro_pushButton_clicked
void MainWindow::on_captureIntro_pushButton_clicked()
{
QString fileName;
QPixmap pixmap;
QPixmap pix;
//this->width ()
//pix = pixmap.grabWidget (this,680,130,300,540); // 獲取當前窗口 (0 , 0, -1, -1)
//获取抓取的横纵坐标
//int grapX= year_lineEdit->geometry ().x ();
//int grapY = year_lineEdit->geometry ().y ();
//使用grabWidget 获取截图 gridLayout_2
pix = pixmap.grabWidget (this->explain_textEdit, 0 ,0, this->explain_textEdit->width (), this->explain_textEdit->height () );
if (pix.isNull())
{
QMessageBox::information(this, "error", "grab Screen failed!", QMessageBox::Ok);
}
else
{
QString path = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if(path!="")
{
fileName = path+"/说明截图.png";
if (!pix.save(fileName, "PNG"))
{
QMessageBox::information(this, "right", "保存失败!", QMessageBox::Ok);
}
else
{
QMessageBox::information(this, "Grab", "保存成功!", QMessageBox::Ok);
}
}
}
}