StepPreviewDialog::StepPreviewDialog(const Step *_target, QWidget *parent) : QDialog(parent), ui(new Ui::StepPreviewDialog) { ui->setupUi(this); QTextEdit *textWidget; QPixmap pic; QLabel *disp; // set the preview widget in accordance to the type switch(_target->Type) { case Step::Text: case Step::Console: textWidget = new QTextEdit(_target->TextContent); textWidget->setReadOnly (true); ui->verticalLayout->addWidget (textWidget, 1); textWidget->show (); break; case Step::Screenshot: pic = QPixmap::fromImage (QImage(_target->ScreenshotPath)); disp = new QLabel(); disp->size ().setHeight (250); disp->size ().setWidth (430); ui->verticalLayout->addWidget (disp, 1); disp->show(); disp->setPixmap (pic.scaled(disp->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); break; default: break; } }
void MainWindow::setThumbnail(int i) { QLabel *screenshotLabel; if (thumbnails[i] == NULL) { screenshotLabel = new QLabel; screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); screenshotLabel->setAlignment(Qt::AlignCenter); screenshotLabel->setMinimumSize(240, 160); layout->addWidget(screenshotLabel, i / 3, i % 3); thumbnails[i] = screenshotLabel; } else { screenshotLabel = thumbnails[i]; } QScreen *srn = QApplication::screens().at(0); QPixmap workspacePixmap = srn->grabWindow(QApplication::desktop()->winId()); screenshotLabel->setPixmap( workspacePixmap.scaled( screenshotLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); }
void DragDropArea::mousePressEvent(QMouseEvent *event) { QLabel *child = static_cast<QLabel*>(childAt(event->pos())); if (!child) return; // Only drag children with dynamic property: "drag" if (!child->property("drag").toBool()) return; QPoint hotSpot = event->pos() - child->pos(); QMimeData *mimeData = new QMimeData; mimeData->setText(child->text()); mimeData->setData("application/x-hotspot", QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y())); QPixmap pixmap(child->size()); child->render(&pixmap); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); drag->setHotSpot(hotSpot); drag->exec(); }
/*! \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()); }
/** * @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()); }
PasswordDialog *PasswordDialog::getPassword(QWidget *parent, const QString &windowTitle, const QString &description, const QString &errorMessage) { auto d = new PasswordDialog(parent); d->setWindowTitle(windowTitle); d->ui.descriptionLabel->setText(description); d->ui.passwordLineEdit->setEchoMode(QLineEdit::Password); // fight the word wrapping beast, also see below int l,r,t,b; // we're gonna need the horizontal margins d->ui.verticalLayout->getContentsMargins(&l,&t,&r,&b); QList<QLabel*> fixedLabels; // and the labels we adjusted // 1. fix the dialog width, assuming to be wanted. d->setMinimumWidth(d->width()); // 2. fix the label width fixedLabels << d->ui.descriptionLabel; // NOTICE: d->ui.descriptionLabel is inside a grid layout, which however has 0 margins d->ui.descriptionLabel->setMinimumWidth(d->width() - (l+r)); // 3. have QLabel figure the size for that width and the content d->ui.descriptionLabel->adjustSize(); // 4. make the label a fixed size element d->ui.descriptionLabel->setFixedSize(d->ui.descriptionLabel->size()); d->adjustSize(); if (!errorMessage.isEmpty()) { QLabel *errorLabel = new QLabel(d); d->ui.verticalLayout->insertWidget(0, errorLabel); errorLabel->setWordWrap(true); errorLabel->setText(errorMessage + QLatin1String("\n<hr>")); errorLabel->setTextFormat(Qt::RichText); // wordwrapping labels are a problem of its own fixedLabels << errorLabel; errorLabel->setMinimumWidth(d->width() - (l+r)); errorLabel->adjustSize(); errorLabel->setFixedSize(errorLabel->size()); } d->adjustSize(); d->setMinimumWidth(0); foreach(QLabel *label, fixedLabels) { label->setMinimumSize(0, 0); label->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); }
/*! \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(); }
PasswordDialog::PasswordDialog(const char *head, QWidget* parent, const char* name, bool modal, WFlags wflags) : QDialog(parent, name, modal, wflags) { debugT("Here we go!!\n"); _head = head; // (David) Layout management QVBoxLayout *vLay = new QVBoxLayout(this, 10 /* border */, 5); // // Bei Bedarf einen kleinen Kommentar als Label einfuegen // English please !!! David. if (_head) { QLabel *l; l = new QLabel(_head, this); l->adjustSize(); l->setMinimumSize(l->size()); vLay->addWidget(l); // l->setGeometry( 10, 10, 200, 20 ); } // The horizontal layout for label + lineedit QHBoxLayout *hLay = new QHBoxLayout(5); vLay->addLayout(hLay); // // Die eine oder zwei Zeile(n) mit der Passwortabfrage // QLabel *l_password = new QLabel(klocale->translate("Password"), this); l_password->adjustSize(); l_password->setMinimumSize(l_password->size()); hLay->addWidget(l_password,0); //l_password->setGeometry( 10, 40, 80, 30 ); _w_password = new QLineEdit( this ); //_w_password->setGeometry( 90, 40, 100, 30 ); _w_password->setEchoMode( QLineEdit::Password ); _w_password->adjustSize(); _w_password->setFixedHeight(_w_password->height()); hLay->addWidget(_w_password,10); // // Connect vom LineEdit herstellen und Accelerator // QAccel *ac = new QAccel(this); ac->connectItem( ac->insertItem(Key_Escape), this, SLOT(reject()) ); connect( _w_password, SIGNAL(returnPressed()), SLOT(accept()) ); // // Eine vertikale Linie erzeugen // QFrame *f = new QFrame(this); f->setLineWidth(1); f->setMidLineWidth(1); f->setFrameStyle( QFrame::HLine|QFrame::Raised); //f->setGeometry( 10, 80, 180, 2 ); f->setMinimumHeight(5); vLay->addWidget(f,0); // // Die Buttons "OK" & "Cancel" erzeugen // QHBoxLayout *hBLay = new QHBoxLayout(5); vLay->addLayout(hBLay); hBLay->addStretch(); QPushButton *b1, *b2; b1 = new QPushButton(klocale->translate("OK"), this); //b1->setGeometry( 10, 90, 80, 30 ); b1->adjustSize(); b1->setFixedSize(b1->size()); hBLay->addWidget(b1); hBLay->addStretch(); //or hBLay->addSpacing(10); b2 = new QPushButton(klocale->translate("Cancel"), this); //b2->setGeometry( 110, 90, 80, 30 ); b2->adjustSize(); b2->setFixedSize(b2->size()); hBLay->addWidget(b2); hBLay->addStretch(); // Buttons mit Funktionaliataet belegen connect( b1, SIGNAL(clicked()), SLOT(accept()) ); connect( b2, SIGNAL(clicked()), SLOT(reject()) ); // Fenstertitel setCaption(klocale->translate("Password")); // Focus _w_password->setFocus(); vLay->activate(); setMinimumSize(200, 50); setMaximumSize(300, 100); debugT("Hi folks, thats it\n"); }
KFontChooser::KFontChooser( QWidget *parent, const char *name ) : QWidget( parent, name ) { int i; fnt = QFont( "helvetica", 12 ); changed = False; QBoxLayout *topLayout = new QVBoxLayout( this, 10, 5 ); topLayout->addStretch( 5 ); QBoxLayout *stackLayout = new QVBoxLayout( 4 ); topLayout->addLayout( stackLayout ); cmbFont = new QComboBox( false, this ); cmbFont->setFixedHeight( cmbFont->sizeHint().height() ); getFontList( fixedList, true ); getFontList( fontList ); cmbFont->insertStrList( &fontList ); QStrListIterator it( fontList ); for ( i = 0; it.current(); ++it, i++ ) { if ( !strcmp( fnt.family(), it.current() ) ) cmbFont->setCurrentItem( i ); } connect( cmbFont, SIGNAL( activated( const char * ) ), SLOT( slotSelectFont( const char * ) ) ); QLabel *label = new QLabel( cmbFont, i18n("&Typeface"), this ); label->adjustSize(); label->setMinimumSize( label->size() ); stackLayout->addWidget( label ); stackLayout->addWidget( cmbFont ); cbBold = new QCheckBox( i18n("&Bold"), this ); cbBold->setMinimumSize( cbBold->sizeHint() ); cbBold->setChecked( fnt.bold() ); connect( cbBold, SIGNAL( toggled( bool ) ), SLOT( slotFontBold( bool ) ) ); topLayout->addWidget( cbBold ); cbItalic = new QCheckBox( i18n("&Italic"), this ); cbItalic->setMinimumSize( cbItalic->sizeHint() ); cbItalic->setChecked( fnt.italic() ); connect( cbItalic, SIGNAL( toggled( bool ) ), SLOT( slotFontItalic( bool ) ) ); topLayout->addWidget( cbItalic ); QBoxLayout *pushLayout = new QHBoxLayout( 2 ); topLayout->addLayout( pushLayout ); stackLayout = new QVBoxLayout( 4 ); pushLayout->addLayout( stackLayout, 10 ); pushLayout->addSpacing( 10 ); sbSize = new KNumericSpinBox( this ); sbSize->setStep( 1 ); sbSize->setRange( 8, 16 ); sbSize->setValue( 12 ); sbSize->adjustSize(); connect( sbSize, SIGNAL( valueDecreased() ), SLOT( slotFontSize() ) ); connect( sbSize, SIGNAL( valueIncreased() ), SLOT( slotFontSize() ) ); label = new QLabel( sbSize, i18n("&Size"), this ); label->setMinimumSize( label->sizeHint() ); cmbCharset = new QComboBox( false, this ); cmbCharset->adjustSize(); cmbCharset->setInsertionPolicy( QComboBox::NoInsertion ); connect( cmbCharset, SIGNAL( activated( const char * ) ), SLOT( slotCharset( const char * ) ) ); sbSize->setFixedHeight( cmbCharset->height() ); sbSize->setMinimumWidth(sbSize->width()); cmbCharset->setFixedHeight( cmbCharset->height() ); cmbCharset->setMinimumWidth( cmbCharset->width()); stackLayout->addWidget( label ); stackLayout->addWidget( sbSize ); stackLayout = new QVBoxLayout( 4 ); pushLayout->addLayout( stackLayout, 30 ); label = new QLabel( cmbCharset, i18n("&Character set"), this ); label->adjustSize(); label->setMinimumSize( label->size() ); stackLayout->addWidget( label ); stackLayout->addWidget( cmbCharset ); topLayout->activate(); fillCharsetCombo(); }