当前位置: 首页>>代码示例>>C++>>正文


C++ QLabel::pixmap方法代码示例

本文整理汇总了C++中QLabel::pixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ QLabel::pixmap方法的具体用法?C++ QLabel::pixmap怎么用?C++ QLabel::pixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QLabel的用法示例。


在下文中一共展示了QLabel::pixmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eventFilter

bool SelectAvatarWidget::eventFilter(QObject *obj, QEvent * event)
{
	if (event->type() == QEvent::MouseButtonPress)
	{
		QLabel * clickedLabel = qobject_cast<QLabel*>(obj);
		if (clickedLabel->pixmap())
		{
			QImage img = clickedLabel->pixmap()->toImage();
			emit avatarSelected(img);
		}
	}
	return QWidget::eventFilter(obj, event);
}
开发者ID:Rambler-ru,项目名称:Contacts,代码行数:13,代码来源:selectavatarwidget.cpp

示例2: mousePressEvent

void MainWindow::mousePressEvent(QMouseEvent *event)
{
    //1,获取图片
    QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
    if(!child->inherits("QLabel")) return;
    QPixmap pixmap = *child->pixmap();
    //2,自定义MIME类型
    QByteArray itemData;
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    dataStream<<pixmap<<QPoint(event->pos()-child->pos());
    //3,将数据放入QMimeData中
    QMimeData *mimeData = new QMimeData;
    mimeData->setData("image/png", itemData);
    //4,将数据放到QDrag中
    QDrag *drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(pixmap);
    drag->setHotSpot(event->pos()-child->pos());
    //5,原图添加阴影
    QPixmap tempPixmap = pixmap;
    QPainter painter;
    painter.begin(&tempPixmap);
    painter.fillRect(pixmap.rect(),QColor(127,127,127,127));
    painter.end();
    child->setPixmap(tempPixmap);
    //6,执行拖放操作
    if(drag->exec(Qt::CopyAction|Qt::MoveAction, Qt::CopyAction)
        ==Qt::MoveAction)
        child->close();
    else{
        child->show();
        child->setPixmap(pixmap);
    }
}
开发者ID:enbool,项目名称:test4,代码行数:34,代码来源:mainwindow.cpp

示例3: HandleMouseEventFromCanvas

    void TerrainWeightEditor::HandleMouseEventFromCanvas(QMouseEvent *ev, QString name)
    {
        if(ev->buttons() && Qt::LeftButton)
        {
            QLabel *canvas = editor_widget_->findChild<QLabel *>(name);
            if(!canvas)
                return;
            QImage image = canvas->pixmap()->toImage();

            //in canvas space, between [0,1]
            qreal brush_pos_x = ev->posF().x()/canvas->width();
            qreal brush_pos_y = ev->posF().y()/canvas->height();

            //in image space (texel coordinates)
            brush_pos_x = brush_pos_x*image.width();
            brush_pos_y = brush_pos_y*image.height();

            qreal half_brush_size = brush_size_*0.5f;

            int start_pos_x = brush_pos_x-half_brush_size;
            int start_pos_y = brush_pos_y-half_brush_size;
            int end_pos_x = brush_pos_x+half_brush_size;
            int end_pos_y = brush_pos_y+half_brush_size;

            //check limits
            start_pos_x = start_pos_x<0?0:start_pos_x;
            start_pos_y = start_pos_y<0?0:start_pos_y;
            end_pos_x = end_pos_x<image.width()? end_pos_x:image.width();
            end_pos_y = end_pos_y<image.height()? end_pos_y:image.height();

            for(int x = start_pos_x; x<end_pos_x;x++)
            {
                for(int y = start_pos_y; y<end_pos_y;y++)
                {
                    QRgb color = image.pixel(x,y);

                    f32 dist = sqrt(pow(x-brush_pos_x,2)+pow(y-brush_pos_y,2));
                    if(dist>half_brush_size)
                        continue;

                    int mod = abs(brush_modifier_) - abs(dist*(brush_modifier_*falloff_percentage_));

                    if(mod<1)
                        continue;

                    if(brush_modifier_<0)
                        mod = -mod;
                    int new_col = qBlue(color)+mod;
                    
                    //Limits (again)
                    new_col = new_col>255?255:new_col;
                    new_col = new_col<0?0:new_col;

                    image.setPixel(x,y, QColor(new_col,new_col,new_col).rgb());

                }
            }
            canvas->setPixmap(QPixmap::fromImage(image));
        }
    }
开发者ID:A-K,项目名称:naali,代码行数:60,代码来源:TerrainWeightEditor.cpp

示例4: imageSize

/*! \internal */
QSize QAccessibleDisplay::imageSize()
{
    QLabel *label = qobject_cast<QLabel *>(widget());
    if (!label)
        return QSize();
    const QPixmap *pixmap = label->pixmap();
    if (!pixmap)
        return QSize();
    return pixmap->size();
}
开发者ID:RS102839,项目名称:qt,代码行数:11,代码来源:simplewidgets.cpp

示例5: imagePosition

/*! \internal */
QRect QAccessibleDisplay::imagePosition() const
{
    QLabel *label = qobject_cast<QLabel *>(widget());
    if (!label)
        return QRect();
    const QPixmap *pixmap = label->pixmap();
    if (!pixmap)
        return QRect();

    return QRect(label->mapToGlobal(label->pos()), label->size());
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:12,代码来源:simplewidgets.cpp

示例6: role

/*! \reimp */
QAccessible::Role Q3AccessibleDisplay::role(int child) const
{
    QLabel *l = qobject_cast<QLabel*>(object());
    if (l) {
        if (l->pixmap() || l->picture())
            return Graphic;
        if (l->picture())
            return Graphic;
        if (l->movie())
            return Animation;
    }
    return QAccessibleWidget::role(child);
}
开发者ID:Marforius,项目名称:qt,代码行数:14,代码来源:q3simplewidgets.cpp

示例7: eventFilter

		bool eventFilter(QObject *obj, QEvent *event) {
			if ( event->type() == QEvent::Paint ) {
				QLabel *l = static_cast<QLabel*>(obj);
				QPainter painter(l);

				int sep = 20;//l->height()*40/100;
				QLinearGradient grad(0,0,0,sep);
				grad.setColorAt(0,midBg);
				grad.setColorAt(0.25,midLightBg);
				grad.setColorAt(1,midLightBg);
				painter.fillRect(0,0,l->width(),sep,grad);

				grad = QLinearGradient(0,sep,0,40);//l->height());
				grad.setColorAt(0,midLightBg);
				grad.setColorAt(0.25,midBg);
				grad.setColorAt(1,midBg);
				painter.fillRect(0,sep,l->width(),l->height()-sep,grad);

				painter.setPen(borderBg);
				painter.drawLine(0,0,l->width(),0);
				/*
				painter.setPen(Qt::black);
				painter.drawLine(0,0,0,l->height());
				painter.drawLine(0,0,l->width(),0);
				*/

				if ( !l->text().isEmpty() ) {
					grad = QLinearGradient(0,0,l->width(),0);
					grad.setColorAt(0, QColor(255,255,255,0));
					grad.setColorAt(0.25, QColor(255,255,255,128));
					grad.setColorAt(0.5, QColor(255,255,255,192));
					grad.setColorAt(0.75, QColor(255,255,255,128));
					grad.setColorAt(1, QColor(255,255,255,0));
					painter.fillRect(0,l->height()-1,l->width(),1,grad);
				}

				const QPixmap *pm = l->pixmap();
				if ( pm != NULL ) {
					int xofs = (l->width() - pm->width()) / 2;
					int yofs = (l->height() - pm->height()) / 2;
					painter.drawPixmap(xofs,yofs, *pm);
				}

				painter.setPen(Qt::white);
				painter.drawText(l->rect().adjusted(20,0,0,0), Qt::AlignLeft | Qt::AlignVCenter, l->text());

				return true;
			}

			return QObject::eventFilter(obj, event);
		}
开发者ID:aemanov,项目名称:seiscomp3,代码行数:51,代码来源:gui.cpp

示例8: setImage

/**
 * @brief ImageHandler::setImage
 * @param qLabel
 * @param image
 */
void ImageHandler::setImage(QLabel& qLabel, cv::Mat image, QImage::Format imageFormat){
    cv::Mat convertIm;
    //convert to RGB for QT labels
    if(image.channels() > 1)
        cv::cvtColor(image, convertIm, CV_BGR2RGB);
    else
        convertIm = image;
    //refit the Mat to fit inside the QLabel
    convertIm = refit(qLabel.size(), convertIm);
    QImage im = QImage((const unsigned char*) (convertIm.data),
                       convertIm.cols, convertIm.rows,convertIm.step, imageFormat);
    qLabel.setPixmap(QPixmap::fromImage(im));
    qLabel.resize( qLabel.pixmap()->size());
}
开发者ID:jonghough,项目名称:QtCV,代码行数:19,代码来源:imagehandler.cpp

示例9: createHPBarLayout

QGridLayout* RegularBattleScene::createHPBarLayout(int slot)
{
    QGridLayout *inside = new QGridLayout();
    inside->setMargin(0);
    inside->setSpacing(4);

    gui.nick[slot] = new QLabel();
    gui.nick[slot]->setObjectName("PokemonNick");
    inside->addWidget(gui.nick[slot], 0, 0, 1, 1, Qt::AlignLeft);
    inside->setColumnStretch(0, 100);

    gui.status[slot] = new QLabel();
    inside->addWidget(gui.status[slot], 0, 1);

    gui.gender[slot] = new QLabel();
    if (data()->gen() > 1) {
        inside->addWidget(gui.gender[slot], 0, 2);
    }

    gui.level[slot] = new QLabel();
    gui.level[slot]->setObjectName("PokemonLevel");
    inside->addWidget(gui.level[slot], 0, 3);


    QHBoxLayout *barL = new QHBoxLayout();
    barL->setMargin(0);
    barL->setSpacing(0);
    QLabel *HPIcon = new QLabel();
    HPIcon->setPixmap(gui.theme->sprite("hpsquare"));
    HPIcon->setFixedSize(HPIcon->pixmap()->size());
    barL->addWidget(HPIcon);
    gui.bars[slot] = new QClickPBar();
    gui.bars[slot]->setObjectName("LifePoints"); /* for stylesheets */
    gui.bars[slot]->setRange(0, 100);
    barL->addWidget(gui.bars[slot]);

    inside->addLayout(barL,1,0,1,4);

    int player = data()->player(slot);

    if (data()->role(player) == BattleConfiguration::Player) {
        gui.bars[slot]->setFormat("%v / %m");
        connect(gui.bars[slot], SIGNAL(clicked()), SLOT(changeBarMode()));
    }

    return inside;
}
开发者ID:awecat,项目名称:pokemon-online,代码行数:47,代码来源:regularbattlescene.cpp

示例10: imagePosition

/*! \internal */
QRect QAccessibleDisplay::imagePosition(QAccessible2::CoordinateType coordType)
{
    QLabel *label = qobject_cast<QLabel *>(widget());
    if (!label)
        return QRect();
    const QPixmap *pixmap = label->pixmap();
    if (!pixmap)
        return QRect();

    switch (coordType) {
    case QAccessible2::RelativeToScreen:
        return QRect(label->mapToGlobal(label->pos()), label->size());
    case QAccessible2::RelativeToParent:
        return label->geometry();
    }

    return QRect();
}
开发者ID:RS102839,项目名称:qt,代码行数:19,代码来源:simplewidgets.cpp

示例11: ShowCover

void AlbumCoverChoiceController::ShowCover(const Song& song) {
  QDialog* dialog = new QDialog(this);
  dialog->setAttribute(Qt::WA_DeleteOnClose, true);

  // Use Artist - Album as the window title
  QString title_text(song.albumartist());
  if (title_text.isEmpty()) title_text = song.artist();

  if (!song.album().isEmpty()) title_text += " - " + song.album();

  dialog->setWindowTitle(title_text);

  QLabel* label = new QLabel(dialog);
  label->setPixmap(AlbumCoverLoader::TryLoadPixmap(
      song.art_automatic(), song.art_manual(), song.url().toLocalFile()));

  dialog->resize(label->pixmap()->size());
  dialog->show();
}
开发者ID:RaoulChartreuse,项目名称:Clementine,代码行数:19,代码来源:albumcoverchoicecontroller.cpp

示例12: ShowCover

void AlbumCoverChoiceController::ShowCover(const Song& song) {
  QDialog* dialog = new QDialog(this);
  dialog->setAttribute(Qt::WA_DeleteOnClose, true);

  // Use (Album)Artist - Album as the window title
  QString title_text(song.effective_albumartist());
  if (!song.effective_album().isEmpty())
    title_text += " - " + song.effective_album();

  QLabel* label = new QLabel(dialog);
  label->setPixmap(AlbumCoverLoader::TryLoadPixmap(
      song.art_automatic(), song.art_manual(), song.url().toLocalFile()));

  // add (WxHpx) to the title before possibly resizing
  title_text += " (" + QString::number(label->pixmap()->width()) + "x" +
                QString::number(label->pixmap()->height()) + "px)";

  // if the cover is larger than the screen, resize the window
  // 85% seems to be enough to account for title bar and taskbar etc.
  QDesktopWidget desktop;
  int current_screen = desktop.screenNumber(this);
  int desktop_height = desktop.screenGeometry(current_screen).height();
  int desktop_width = desktop.screenGeometry(current_screen).width();

  // resize differently if monitor is in portrait mode
  if (desktop_width < desktop_height) {
    const int new_width = (double)desktop_width * 0.95;
    if (new_width < label->pixmap()->width()) {
      label->setPixmap(
          label->pixmap()->scaledToWidth(new_width, Qt::SmoothTransformation));
    }
  } else {
    const int new_height = (double)desktop_height * 0.85;
    if (new_height < label->pixmap()->height()) {
      label->setPixmap(label->pixmap()->scaledToHeight(
          new_height, Qt::SmoothTransformation));
    }
  }

  dialog->setWindowTitle(title_text);
  dialog->setFixedSize(label->pixmap()->size());
  dialog->show();
}
开发者ID:Chemrat,项目名称:Clementine,代码行数:43,代码来源:albumcoverchoicecontroller.cpp

示例13: role

/*! \reimp */
QAccessible::Role QAccessibleDisplay::role(int child) const
{
    QLabel *l = qobject_cast<QLabel*>(object());
    if (l) {
        if (l->pixmap())
            return Graphic;
#ifndef QT_NO_PICTURE
        if (l->picture())
            return Graphic;
#endif
#ifndef QT_NO_MOVIE
        if (l->movie())
            return Animation;
#endif
#ifndef QT_NO_PROGRESSBAR
    } else if (qobject_cast<QProgressBar*>(object())) {
        return ProgressBar;
#endif
    }
    return QAccessibleWidgetEx::role(child);
}
开发者ID:RS102839,项目名称:qt,代码行数:22,代码来源:simplewidgets.cpp

示例14: QFrame

OptionsHeader::OptionsHeader(const QString &AIconKey, const QString &ACaption, QWidget *AParent) : QFrame(AParent)
{
	setObjectName("wdtOptionsHeader");

	QHBoxLayout *hlayout = new QHBoxLayout(this);
	hlayout->setContentsMargins(0,hlayout->spacing()*1.5,0,0);

	QLabel *icon = new QLabel(this);
	icon->setObjectName("optionsIconLabel");
	icon->setFixedSize(20,20);
	IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->insertAutoIcon(icon,AIconKey,0,0,"pixmap");
	hlayout->addWidget(icon);
	if (!icon->pixmap())
		icon->setVisible(false);

	QLabel *caption = new QLabel(this);
	caption->setObjectName("optionsCaptionLabel");
	caption->setText(ACaption);
	hlayout->addWidget(caption);

	hlayout->addStretch();
}
开发者ID:Rambler-ru,项目名称:Contacts,代码行数:22,代码来源:optionsheader.cpp

示例15: QLabel

QWidget *RegularBattleScene::createFullBarLayout(int nslots, int player)
{
    QLabel* oppPoke = new QLabel();
    oppPoke->setPixmap(gui.theme->sprite("hpbar"));
    oppPoke->setFixedSize(oppPoke->pixmap()->size());

    QVBoxLayout *oppl = new QVBoxLayout(oppPoke);
    oppl->setMargin(5);
    oppl->setSpacing(0);
    oppl->addSpacing(3);

    QHBoxLayout *oppl2 = new QHBoxLayout();
    oppl->addLayout(oppl2);
    oppl2->setMargin(0);
    oppl2->setSpacing(6);

    for (int i = 0; i < nslots/2; i++) {
        oppl2->addLayout(createHPBarLayout(data()->spot(player, i)));
    }

    return oppPoke;
}
开发者ID:awecat,项目名称:pokemon-online,代码行数:22,代码来源:regularbattlescene.cpp


注:本文中的QLabel::pixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。