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); }
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); } }
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)); } }
/*! \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(); }
/*! \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()); }
/*! \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); }
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); }
/** * @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()); }
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; }
/*! \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(); }
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(); }
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(); }
/*! \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); }
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(); }
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; }
void MainWindow::mousePressEvent(QMouseEvent *event){ // imprimindo mensagem de debug qDebug()<<"MainWindow::mousePressEvent(QMouseEvent *event)"; QLabel *label = static_cast<QLabel*>(childAt(event->pos())); if (!label || label->objectName()=="centralWidget" || label->objectName()=="" || label->objectName()=="diagrama"){ return; } // imprimindo mensagem para debug qDebug()<<label->objectName(); QPixmap pixmap = *label->pixmap(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << pixmap << QPoint(event->pos() - label->pos()); QMimeData *mimeData = new QMimeData(); mimeData->setData("application/x-dnditemdata", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(event->pos() - label->pos()); QPoint pointAtual = event->pos(); if(pointAtual.x() > ui->diagrama->geometry().x() && pointAtual.y() > ui->diagrama->geometry().y() && pointAtual.x() < ui->diagrama->width()) { label->close(); } if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) { label->show(); label->setPixmap(pixmap); } }
TeamPokeButton::TeamPokeButton(int num, Pokemon::uniqueId poke, int level, int item) { this->m_num = num; setObjectName("PokeButton"); setAcceptDrops(true); setCheckable(true); setAccessibleName(tr("Pokemon slot %1", "TB accessible name").arg(QString::number(num))); QGridLayout *ml = new QGridLayout(this); ml->setMargin(2); ml->setSpacing(2); QLabel *pokeBG = new QLabel(); pokeBG->setPixmap(Theme::FrameBall()); pokeBG->setFixedSize(pokeBG->pixmap()->size()); pokeIcon = new QLabel(pokeBG); pokeIcon->move(7,3); ml->addWidget(pokeBG,0,0,3,1); QLabel * pokeText = new QLabel(tr("Pokémon &%1").arg(num+1)); pokeText->setObjectName("NormalText"); pokeText->setBuddy(this); ml->addWidget(pokeText, 0,1,1,2); ml->addWidget(this->level = new QLabel(),1,1,1,2); this->level->setObjectName("SmallText"); QLabel *iteml; ml->addWidget(iteml = new QLabel(tr("Item")), 2,1,1,1, Qt::AlignLeft); iteml->setObjectName("SmallText"); ml->addWidget(itemIcon = new QLabel(), 2,2,1,1, Qt::AlignRight); itemIcon->setFixedSize(24,24); changeInfos(poke, level, item); }
std::vector<QHBoxLayout *> ActiveLearningDialog::Sample_Details(QImage snapshot, vtkSmartPointer<vtkTable> table,int num_classes,int active_query,std::vector<int>top_feats,int group) { QLabel *imageLabel = new QLabel(this); imageLabel->setPixmap(QPixmap::fromImage(snapshot)); imageLabel->resize(imageLabel->pixmap()->size()); finish = true; //Top-row of the window QHBoxLayout *topRow = new QHBoxLayout; topRow->addWidget(imageLabel,0,0); QLabel *enterClassLabel = new QLabel("Select Class: ", this); topRow->addWidget(enterClassLabel,0,0); buttongroup[group] = new QButtonGroup(this); buttongroup[group]->setExclusive(true); // radiobutons for each class for(int i =0 ; i< num_classes ; ++i) { QRadioButton *class_button = new QRadioButton(QString::number(i + 1), this); topRow->addWidget(class_button,0,0); button_vector.push_back(class_button); buttongroup[group]->addButton(class_button); connect(class_button, SIGNAL(clicked()),this,SLOT(Set_Class())); } QRadioButton *class_button = new QRadioButton("I am not sure" , this); connect(class_button, SIGNAL(clicked()),this,SLOT(Set_Class())); button_vector.push_back(class_button); buttongroup[group]->addButton(class_button); topRow->addWidget(class_button,0,0); //Remove the train column table->RemoveColumnByName("train"); int numb_cols = MIN(5,table->GetNumberOfColumns()); QStringList sl; for(int i=0;i<numb_cols;++i) { sl<<QString(table->GetColumnName(top_feats[i])); } // Table displaying 5 top features QTableWidget *tableWidget = new QTableWidget(1, numb_cols, this); tableWidget->setHorizontalHeaderLabels(sl); tableWidget->setRowCount(1); tableWidget->setColumnCount(numb_cols); for(int i=0;i<numb_cols;++i) { QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(table->GetValue(active_query,top_feats[i]).ToDouble())); newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable); tableWidget->setItem(0, i, newItem); } //classes_chosen.resize(num_classes+1); //for(int i =0 ; i<=num_classes ; ++i) //{ // classes_chosen[i] = -1;// Used to check if no radiobutton was selected for any sample //} //Bottom-row of the window QHBoxLayout *botRow = new QHBoxLayout; botRow->addWidget(tableWidget,0,0); //botRow->addWidget(channelLabel,1,0); std::vector<QHBoxLayout *> rows; rows.push_back(topRow); rows.push_back(botRow); return rows; }
IMT_MRGui::IMT_MRGui(QWidget *parent) : QMainWindow(parent), ui(new Ui::IMT_MRGui) { // Initialize the first GPU GPU0_.allocateGPU(0); GPU0_.printInformation(std::cout); size_t free; size_t total; cuMemGetInfo(&free, &total); std::cout << "free memory: " << free / 1024 / 1024 << "mb, total memory: " << total / 1024 / 1024 << "mb" << std::endl; ui->setupUi(this); read_siemens = 0; fftobj_ = new agile::FFT<TType>(); kspacefovobj_ = new agile::KSpaceFOV<TType>(); open_irgnpara_window = new IRGN_para(); // Be sure to destroy you window somewhere open_irgnpara_window->hide(); _pathsetting = new PathSetting(); // Be sure to destroy you window somewhere _pathsetting->hide(); _specialsetting = new SpecialSetting(); // Be sure to destroy you window somewhere _specialsetting->hide(); setStatusBar(); setTitleText(""); future = new QFuture<void>; watcher = new QFutureWatcher<void>; _cycleread_thread = new CycleRead; _cycleread_thread->set_max_acq_time(_specialsetting->get_autoload_timeout()); _infotext=""; QObject::connect(this,SIGNAL(sendInfo(QString, bool)),this,SLOT(set_Info(QString, bool))); QObject::connect(this,SIGNAL(sendWarning(QString)),this,SLOT(set_Warning(QString))); QObject::connect(this,SIGNAL(sendSaveFile(QString,QString)),this,SLOT(set_SaveFile(QString,QString)),Qt::BlockingQueuedConnection); QObject::connect(_cycleread_thread, SIGNAL(send_filenames(QStringList, QStringList)), this, SLOT(startauto(QStringList, QStringList))); _act_index = 0; _automatic_on = false; _write_file_index=0; ui->cb_savingtype->setCurrentIndex(2); ui->pb_automatic->setText("Auto Off"); _postprocess = new agile::PostProcess<TType, TType_real>(); QLabel* imageLabel = new QLabel(this); imageLabel->setBackgroundRole(QPalette::Base); imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); imageLabel->setScaledContents(true); QImage image(":/images/wappen.png"); imageLabel->setPixmap(QPixmap::fromImage(image)); imageLabel->resize(imageLabel->pixmap()->size()); imageLabel->setGeometry((this->width() - imageLabel->sizeHint().width()), 40, imageLabel->sizeHint().width(), imageLabel->sizeHint().height()); imageLabel->show(); }
std::vector<QHBoxLayout *> ActiveLearningDialog::Validation_Sample_Details(QImage snapshot, vtkSmartPointer<vtkTable> table,int classval,int PIA_query,int group,int num_classes) { QLabel *imageLabel = new QLabel(this); imageLabel->setPixmap(QPixmap::fromImage(snapshot)); imageLabel->resize(imageLabel->pixmap()->size()); finish = true; //Top-row of the window QHBoxLayout *topRow = new QHBoxLayout; topRow->addWidget(imageLabel,0,0); QLabel *enterClassLabel = new QLabel("Please indicate the correct class: ", this); topRow->addWidget(enterClassLabel,0,0); buttongroup[group] = new QButtonGroup(this); buttongroup[group]->setExclusive(true); // radiobutons for each class for(int i =0 ; i< num_classes ; ++i) { QRadioButton *class_button = new QRadioButton(QString::number(i), this); if(i+1==classval) class_button->setChecked(true); topRow->addWidget(class_button,0,0); button_vector.push_back(class_button); buttongroup[group]->addButton(class_button); connect(class_button, SIGNAL(clicked()),this,SLOT(Set_Class_Validate())); } //QRadioButton *class_button = new QRadioButton("I am not sure" , this); //connect(class_button, SIGNAL(clicked()),this,SLOT(Set_Class())); //button_vector.push_back(class_button); //buttongroup[group]->addButton(class_button); //topRow->addWidget(class_button,0,0); QStringList sl; for(int i=0;i<table->GetNumberOfColumns();++i) { sl<<QString(table->GetColumnName(i)); } // Table displaying features of the sample QTableWidget *tableWidget = new QTableWidget(1, table->GetNumberOfColumns(), this); tableWidget->setHorizontalHeaderLabels(sl); tableWidget->setRowCount(1); tableWidget->setColumnCount(table->GetNumberOfColumns()); for(int i=0;i<table->GetNumberOfColumns();++i) { QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(table->GetValue(PIA_query,i).ToDouble())); newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable); tableWidget->setItem(0, i, newItem); } //Bottom-row of the window QHBoxLayout *botRow = new QHBoxLayout; botRow->addWidget(tableWidget,0,0); //botRow->addWidget(channelLabel,1,0); std::vector<QHBoxLayout *> rows; rows.push_back(topRow); rows.push_back(botRow); return rows; }
bool event(QEvent* event) { if (event->type() == QEvent::User) { FrameEvent* frameEvent = (FrameEvent*)event; if (close && frameEvent->getFrame()->getType() == Frame::typeNormal) { double t = 1.0+frameId; Frame frame_t = *frameEvent->getFrame(); if (frameId) { meanFrame *= (t-1.0)/t; meanFrame += frame_t*(1.0/t); varianceFrame *= (t-1.0)/t; frame_t -= meanFrame; frame_t *= frame_t; frame_t *= 1.0/(t-1.0); varianceFrame += frame_t; } else { meanFrame = frame_t*(1.0/t); varianceFrame.resize(meanFrame.getWidth(), meanFrame.getHeight()); } ++frameId; } if (frameEvent->getFrame()->getType() == Frame::typeNormal) { frame = *frameEvent->getFrame(); size_t width = frame.getWidth(); size_t height = frame.getHeight(); if (!calibrationFrame.isEmpty()) frame -= calibrationFrame; else if (!lastCalibrationFrame.isEmpty()) frame -= lastCalibrationFrame; float epsilon = std::numeric_limits<float>::epsilon(); if (!varianceFrame.isEmpty()) { for (size_t x = 0; x < width; ++x) for (size_t y = 0; y < height; ++y) if (varianceFrame(x, y) < epsilon) frame.close(x, y); } frame.normalize(); if (blur) frame.gaussianBlur(); QImage image(width, height, QImage::Format_RGB888); for (size_t x = 0; x < width; ++x) for (size_t y = 0; y < height; ++y) { float value = frame(x, y)*255.0; image.setPixel(x, y, qRgb(value, value, value)); } label.setPixmap(QPixmap::fromImage( image.scaled(image.size()*scale))); setFixedSize(label.pixmap()->width(), label.pixmap()->height()+ statusBar.height()); if (underMouse()) updateValue(centralWidget()->mapFromGlobal(QCursor::pos())); } else if (frameEvent->getFrame()->getType() == Frame::typeCalibration) lastCalibrationFrame = *frameEvent->getFrame(); } else QMainWindow::event(event); }
void addTab(std::string tabName, ImageStorage* imgstore, Ui::MainWindow *ui) { /*ui->processBtn->setEnabled(true); ui->previousBtn->setEnabled(true);*/ QWidget *tab = new QWidget(); QString qname = QString::fromStdString(tabName); tab->setObjectName(qname); QHBoxLayout *horizontalLayout = new QHBoxLayout(tab); horizontalLayout->setSpacing(6); horizontalLayout->setContentsMargins(11, 11, 11, 11); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); QScrollArea * scrollArea = new QScrollArea(tab); scrollArea->setObjectName(QStringLiteral("scrollArea")); scrollArea->setWidgetResizable(true); QWidget * scrollAreaWidgetContents = new QWidget(); scrollAreaWidgetContents->setObjectName(QStringLiteral("scrollAreaWidgetContents")); scrollAreaWidgetContents->setGeometry(QRect(0, 0, 492, 447)); QHBoxLayout* horizontalLayout_13 = new QHBoxLayout(scrollAreaWidgetContents); horizontalLayout->setSpacing(6); horizontalLayout_13->setContentsMargins(11, 11, 11, 11); horizontalLayout_13->setObjectName(QStringLiteral("horizontalLayout_13")); QLabel* label = new QLabel(scrollAreaWidgetContents); std::string stmp = tabName; stmp.append("_label"); QString qname2 = QString::fromStdString(stmp); label->setObjectName(qname2); QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding); sizePolicy2.setHorizontalStretch(0); sizePolicy2.setVerticalStretch(0); sizePolicy2.setHeightForWidth(label->sizePolicy().hasHeightForWidth()); label->setSizePolicy(sizePolicy2); horizontalLayout_13->addWidget(label); scrollArea->setWidget(scrollAreaWidgetContents); horizontalLayout->addWidget(scrollArea); ui->imageTab->addTab(tab, QString()); std::string tmp1 = tabName.c_str(); const char* tmp2 = tmp1.c_str(); ui->imageTab->setTabText(ui->imageTab->indexOf(tab), QApplication::translate("MainWindow", tmp2, 0)); ui->imageTab->setCurrentIndex(ui->imageTab->indexOf(tab)); //------------------------- //--------------------- //display image cv::Mat image = std::get<1>(imgstore->getCurrent()->second); QImage img; if(image.channels() == 3) // RGB image { //cvtColor(image, image, CV_BGR2RGB); img = QImage((const uchar*)(image.data), //(const unsigned char*) image.cols, image.rows, image.cols*image.channels(), QImage::Format_RGB888); }else // gray image { img = QImage((const uchar*)(image.data), image.cols, image.rows, image.cols*image.channels(), QImage::Format_Indexed8); } if (!img.isNull()) { label->setPixmap(QPixmap::fromImage(img)); label->resize(label->pixmap()->size()); label->setAlignment(Qt::AlignCenter); label->show(); } else { ASSERT(0); } //--------------------- }