void NoteItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyle* style = KApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter); QRect rect = option.rect; rect.adjust( m_margin, m_margin, -m_margin, -m_margin ); Nepomuk2::Resource res = index.data( Nepomuk2::Utils::SimpleResourceModel::ResourceRole ).value<Nepomuk2::Resource>(); QString plainTextContent = res.property( NIE::plainTextContent() ).toString(); QDateTime creationDate = res.property( NAO::created() ).toDateTime(); //TODO: Find a way to convert this date into "4 hours ago" format QString dateString = creationDate.toLocalTime().toString(); painter->save(); QFont f = painter->font(); f.setBold( true ); painter->setFont( f ); style->drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignTop, option.palette, true, dateString ); painter->restore(); rect.setY( rect.y() + QFontMetrics(f).height()/* + m_margin */); // // Draw the excerpt // QTextDocument textDocument; textDocument.setTextWidth( rect.width() ); QFont font = textDocument.defaultFont(); font.setItalic( true ); textDocument.setDefaultFont( font ); QFontMetrics fm( font ); int numLines = rect.height() / fm.height(); int charPerLine = rect.width() / fm.averageCharWidth(); int l = (numLines-2) * charPerLine; // one line less for ending, and one line for padding QString text; // FIXME: There may be a case where some part of the text gets repeated before and after the ... if( l < plainTextContent.length() ) { text = plainTextContent.left( l ); text += QLatin1String(" .... "); text += plainTextContent.right( charPerLine-10 ); } else { text = plainTextContent; } textDocument.setPlainText( text.simplified() ); painter->save(); painter->translate( rect.topLeft() ); textDocument.drawContents( painter ); painter->restore(); }
void RepoItemDelegate::paintRepoCategoryItem(QPainter *painter, const QStyleOptionViewItem& option, const RepoCategoryItem *item) const { QBrush backBrush; QColor foreColor; bool hover = false; bool selected = false; if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = option.palette.brush(QPalette::Highlight); foreColor = option.palette.color(QPalette::HighlightedText); selected = true; } else if (option.state & QStyle::State_MouseOver) { backBrush = option.palette.color(QPalette::Highlight).lighter(115); foreColor = option.palette.color(QPalette::HighlightedText); hover = true; } else { backBrush = option.palette.brush(QPalette::Base); foreColor = option.palette.color(QPalette::Text); } QStyle *style = QApplication::style(); QStyleOptionViewItemV4 opt(option); opt.backgroundBrush = backBrush; painter->save(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, 0); painter->restore(); // Paint the expand/collapse indicator RepoTreeModel *model = (RepoTreeModel *)item->model(); RepoTreeView *view = model->treeView(); bool expanded = view->isExpanded(model->indexFromItem(item)); QRect indicator_rect(option.rect.topLeft(), option.rect.bottomLeft() + QPoint(option.rect.height(), 0)); painter->save(); painter->setPen(foreColor); painter->setFont(awesome->font(16)); painter->drawText(indicator_rect, Qt::AlignCenter, QChar(expanded ? icon_caret_down : icon_caret_right), &indicator_rect); painter->restore(); // Paint category name painter->save(); QPoint category_name_pos = indicator_rect.topRight() + QPoint(kMarginBetweenIndicatorAndName, 0); QRect category_name_rect(category_name_pos, option.rect.bottomRight() - QPoint(kPadding, 0)); painter->setPen(foreColor); painter->drawText(category_name_rect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, fitTextToWidth(item->name(), option.font, category_name_rect.width())); painter->restore(); }
void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index ) const { painter->save(); QTextDocument doc; QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) ); QAbstractTextDocumentLayout::PaintContext ctx; QStyleOptionViewItemV4 optionV4 = option; QColor color; if ( option.state & QStyle::State_Selected && option.state & QStyle::State_HasFocus ) { color = QColor( 255, 255, 255, 60 ); ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::HighlightedText ) ); QStyle *style = QApplication::style(); style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL ); } else if ( option.state & QStyle::State_Enabled ) { color = QColor( 100, 100, 100, 30 ); ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::Text ) ); QStyle *style = QApplication::style(); style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL ); } else { color = QColor( 100, 100, 100, 30 ); ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Disabled, QPalette::Text ) ); } painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( QColor( 0, 0, 0, 0 ) ); painter->setBrush( QBrush( color ) ); painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 ); int titleSize = QApplication::fontMetrics().height() * 1.1; int textSize = titleSize * 0.85; doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ) .arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString(), index.data( QgsWelcomePageItemsModel::PathRole ).toString(), index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) ); doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) ); if ( !icon.isNull() ) { painter->drawPixmap( option.rect.left() + 10, option.rect.top() + 10, icon ); } painter->translate( option.rect.left() + ( !icon.isNull() ? icon.width() + 25 : 15 ), option.rect.top() + 15 ); ctx.clip = QRect( 0, 0, option.rect.width() - ( !icon.isNull() ? icon.width() - 35 : 25 ), option.rect.height() - 25 ); doc.documentLayout()->draw( painter, ctx ); painter->restore(); }
//========================================================================= hTreeBrowser::hTreeBrowser(QWidget *parent, MainWindow * mainWindow) : QTreeWidget (parent) , parent_ (parent->parentWidget()) , theMainWindow_(mainWindow) , currentCanvas_(0) , canvasPosX_ (5) , canvasPosY_ (5) , canvasWitdh_ (800) , canvasHeight_ (600) , currentObject_(0) { // theHManager_ = theMainWindow_->getHManager() ; serviceCanvas_.clear(); cSw_.clear() ; QStringList labels; labels << tr("Folder Name") << tr("Object Type") << tr("Entries"); this->setHeaderLabels(labels); this->header()->setResizeMode(0, QHeaderView::Interactive); this->header()->setResizeMode(1, QHeaderView::Interactive); this->header()->setResizeMode(2, QHeaderView::Interactive); this->header()->setDefaultSectionSize(200); this->setContextMenuPolicy(Qt::CustomContextMenu); QStyle *style = parent_->style(); QString imagesDir = QString(getenv("CHEWIEDIR")) + "/images/"; QPixmap closedFolderPM(imagesDir+"ClosedFolder.png"); QPixmap openFolderPM (imagesDir+"OpenFolder.png" ); QPixmap TH1IconPM (imagesDir+"TH1Icon.png" ); QPixmap TH2IconPM (imagesDir+"TH2Icon.png" ); QPixmap TTreePM (imagesDir+"TreeIcon.png" ); QPixmap TGraphPM (imagesDir+"TGraphIcon.png" ); QPixmap TProfilePM (imagesDir+"TProfileIcon.png"); folderIcon_ .addPixmap(closedFolderPM, QIcon::Normal, QIcon::Off ); folderIcon_ .addPixmap(openFolderPM, QIcon::Normal, QIcon::On ); canvasIcon_ .addPixmap(style->standardPixmap(QStyle::SP_FileIcon )); TH1Icon_ .addPixmap(TH1IconPM ); TH2Icon_ .addPixmap(TH2IconPM ); tTreeIcon_ .addPixmap(TTreePM ); tGraphIcon_ .addPixmap(TGraphPM ); tProfileIcon_.addPixmap(TProfilePM ); mainIcon_ .addPixmap(style->standardPixmap(QStyle::SP_DriveHDIcon )); this->setAnimated(true); this->setSelectionMode(QAbstractItemView::ExtendedSelection); QObject::connect(this, SIGNAL(customContextMenuRequested( const QPoint & )), this, SLOT( showContextMenu ( const QPoint & ))) ; QObject::connect(this, SIGNAL(itemClicked ( QTreeWidgetItem*, int)), this, SLOT( manipulateFolder ( QTreeWidgetItem*, int))) ; //QObject::connect(this, SIGNAL(itemEntered ( QTreeWidgetItem*, int)), // this, SLOT( showHint ( QTreeWidgetItem*, int))) ; }
void ExpandingDelegate::drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_UNUSED(index) QStyleOptionViewItemV4 opt = option; //initStyleOption(&opt, index); //Problem: This isn't called at all, because drawBrackground is not virtual :-/ QStyle *style = model()->treeView()->style() ? model()->treeView()->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter); }
/*! Creates and returns a QStyle object that matches the given \a key, or returns 0 if no matching style is found. Both built-in styles and styles from style plugins are queried for a matching style. \note The keys used are case insensitive. \sa keys() */ QStyle *QStyleFactory::create(const QString& key) { QStyle *ret = 0; QString style = key.toLower(); #ifndef QT_NO_STYLE_WINDOWS if (style == QLatin1String("windows")) ret = new QWindowsStyle; else #endif #ifndef QT_NO_STYLE_WINDOWSCE if (style == QLatin1String("windowsce")) ret = new QWindowsCEStyle; else #endif #ifndef QT_NO_STYLE_WINDOWSMOBILE if (style == QLatin1String("windowsmobile")) ret = new QWindowsMobileStyle; else #endif #ifndef QT_NO_STYLE_WINDOWSXP if (style == QLatin1String("windowsxp")) ret = new QWindowsXPStyle; else #endif #ifndef QT_NO_STYLE_WINDOWSVISTA if (style == QLatin1String("windowsvista")) ret = new QWindowsVistaStyle; else #endif #ifndef QT_NO_STYLE_FUSION if (style == QLatin1String("fusion")) ret = new QFusionStyle; else #endif #ifndef QT_NO_STYLE_GTK if (style == QLatin1String("gtk") || style == QLatin1String("gtk+")) ret = new QGtkStyle; else #endif #ifndef QT_NO_STYLE_MAC if (style.startsWith(QLatin1String("macintosh"))) { ret = new QMacStyle; # ifdef Q_WS_MAC if (style == QLatin1String("macintosh")) style += QLatin1String(" (aqua)"); # endif } else #endif { } // Keep these here - they make the #ifdefery above work #ifndef QT_NO_LIBRARY if (!ret) ret = qLoadPlugin<QStyle, QStylePlugin>(loader(), style); #endif if(ret) ret->setObjectName(style); return ret; }
/*! \brief Gets the suitable size of project window. This size is just suitable for the whole project area with 1px border and the scroll bar. \return suitable size of this project window */ QSize Ui::ProjectWindow::sizeHint() const { QStyle *style = qApp->style(); int frameBorderWidth = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth); int frameTitleHeight = style->pixelMetric(QStyle::PM_TitleBarHeight); int scrollBarWidth = style->pixelMetric(QStyle::PM_ScrollBarExtent); return QSize(view->width() + (frameBorderWidth << 1) + scrollBarWidth + 2, view->height() + frameTitleHeight + frameBorderWidth + statusBar->height() - 10); }
int ViewHelpMenu::getStyle() const { QStyle * style = QApplication::style(); const QMetaObject * mo = style->metaObject(); for(uint i = 0 ; i < __ids.size() ; i++){ if((QStyleFactory::create(__ids[i]->text()))->metaObject() == mo) return i; } return -1; }
void DStyleComboBox::chooseStyle(const QString &style) { QStyle *st = QStyleFactory::create( style ); if(st) { qApp->setStyle( st ); qApp->setPalette(st->standardPalette()); } }
void UserDelegate::paint(QPainter * painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QAbstractItemModel *m = index.model(); const QModelIndex idxc1 = index.sibling(index.row(), 1); QVariant data = m->data(idxc1); QList<QVariant> ql = data.toList(); painter->save(); QStyleOptionViewItemV4 o = option; initStyleOption(&o, index); QStyle *style = o.widget->style(); QIcon::Mode iconMode = QIcon::Normal; QPalette::ColorRole colorRole = ((o.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text); #if defined(Q_OS_WIN) // Qt's Vista Style has the wrong highlight color for treeview items // We can't check for QStyleSheetStyle so we have to search the children list search for a QWindowsVistaStyle QList<QObject *> hierarchy = style->findChildren<QObject *>(); hierarchy.insert(0, style); foreach (QObject *obj, hierarchy) { if (QString::fromUtf8(obj->metaObject()->className()) == QString::fromUtf8("QWindowsVistaStyle")) { colorRole = QPalette::Text; break; } } #endif // draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &o, painter, o.widget); // resize rect to exclude the flag icons o.rect = option.rect.adjusted(0, 0, -18 * ql.count(), 0); // draw icon QRect decorationRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &o, o.widget); o.icon.paint(painter, decorationRect, o.decorationAlignment, iconMode, QIcon::On); // draw text QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &o, o.widget); QString itemText = o.fontMetrics.elidedText(o.text, o.textElideMode, textRect.width()); painter->setFont(o.font); style->drawItemText(painter, textRect, o.displayAlignment, o.palette, true, itemText, colorRole); // draw flag icons to original rect QRect ps = QRect(option.rect.right() - (ql.size() * 18), option.rect.y(), ql.size() * 18, option.rect.height()); for (int i = 0; i < ql.size(); ++i) { QRect r = ps; r.setSize(QSize(16, 16)); r.translate(i * 18 + 1, 1); QRect p = QStyle::alignedRect(option.direction, option.decorationAlignment, r.size(), r); qvariant_cast<QIcon>(ql[i]).paint(painter, p, option.decorationAlignment, iconMode, QIcon::On); } painter->restore(); }
void KOTodoRichTextDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { if ( index.data( KOTodoModel::IsRichTextRole ).toBool() ) { QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, index ); const QWidget *widget = opt.widget; QStyle *style = widget ? widget->style() : QApplication::style(); QRect textRect = style->subElementRect( QStyle::SE_ItemViewItemText, &opt, widget ); // draw the item without text opt.text.clear(); style->drawControl( QStyle::CE_ItemViewItem, &opt, painter, widget ); // draw the text (rich text) QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if ( cg == QPalette::Normal && !( opt.state & QStyle::State_Active ) ) { cg = QPalette::Inactive; } if ( opt.state & QStyle::State_Selected ) { painter->setPen( QPen( opt.palette.brush( cg, QPalette::HighlightedText ), 0 ) ); } else { painter->setPen( QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) ); } if ( opt.state & QStyle::State_Editing ) { painter->setPen( QPen( opt.palette.brush( cg, QPalette::Text ), 0 ) ); painter->drawRect( textRect.adjusted( 0, 0, -1, -1 ) ); } m_textDoc->setHtml( index.data().toString() ); painter->save(); painter->translate( textRect.topLeft() ); QRect tmpRect = textRect; tmpRect.moveTo( 0, 0 ); m_textDoc->setTextWidth( tmpRect.width() ); m_textDoc->drawContents( painter, tmpRect ); painter->restore(); } else { // align the text at top so that when it has more than two lines // it will just cut the extra lines out instead of aligning centered vertically QStyleOptionViewItem copy = option; copy.displayAlignment = Qt::AlignLeft | Qt::AlignTop; QStyledItemDelegate::paint( painter, copy, index ); } }
int PlatformScrollbar::horizontalScrollbarHeight(ScrollbarControlSize controlSize) { QStyle *s = QApplication::style(); QStyleOptionSlider o; o.orientation = Qt::Horizontal; o.state |= QStyle::State_Horizontal; if (controlSize != RegularScrollbar) o.state |= QStyle::State_Mini; return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0); }
int ScrollbarThemeQt::scrollbarThickness(ScrollbarControlSize controlSize) { QStyle* s = QApplication::style(); QStyleOptionSlider o; o.orientation = Qt::Vertical; o.state &= ~QStyle::State_Horizontal; if (controlSize != RegularScrollbar) o.state |= QStyle::State_Mini; return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0); }
XMLParameterReader::XMLParameterReader(QTreeWidget *tree_widget) : tree_widget(tree_widget) { QStyle * style = tree_widget->style(); subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); subsection_icon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); parameter_icon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); }
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; opt.text = defaultDisplayText(index); initStyleOption(&opt, index); const QWidget *widget = this->widget(option); QStyle *style = this->style(option); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); }
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override { QStyle *style = option.widget ? option.widget->style() : QApplication::style(); QString text = index.model()->data(index, static_cast<int>(AppRole::Display)).toString(); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); opt.text = text; style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, option.widget); }
//! [0] XbelReader::XbelReader(QTreeWidget *treeWidget) : treeWidget(treeWidget) { QStyle *style = treeWidget->style(); folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); }
void AccountDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { painter->save(); if (const QStyleOptionViewItemV4 * itemOptionV4 = qstyleoption_cast< const QStyleOptionViewItemV4 * >(&option)) { // Collect option information const QStyleOptionViewItemV3 * optionV3 = qstyleoption_cast< const QStyleOptionViewItemV3 * >(&option); const QWidget * widget = optionV3 ? optionV3->widget : 0; QStyle * style = widget ? widget->style() : QApplication::style(); QStyleOptionViewItemV4 opt(option); initStyleOption(&opt, index); // Draw standard background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget); QPalette::ColorGroup group = (option.state & QStyle::State_Active) ? QPalette::Active : QPalette::Inactive; if (option.state & QStyle::State_Selected) { painter->setPen(option.palette.color(group, QPalette::HighlightedText)); } else { painter->setPen(index.data(Qt::ForegroundRole).value< QBrush >().color()); } // Get textual information QString description(index.data(Qt::DisplayRole).toString()); QString username = "******"; if (static_cast< Qt::CheckState >(index.sibling(index.row(), 0).data(Qt::CheckStateRole).toInt()) == Qt::Checked) { username = index.sibling(index.row(), index.column() + 1).data(Qt::DisplayRole).toString(); } // Draw textual information QFont smaller(option.font); smaller.setPointSizeF(smaller.pointSizeF() * 0.85); smaller.setItalic(true); QFontMetrics smallerMetrics(smaller); int height = row_height(option); int divider = height / 2 + (option.fontMetrics.height() - smallerMetrics.height()) / 2; painter->setBrush(Qt::NoBrush); QRect descriptionRect = option.rect; int flags = Qt::AlignLeft | Qt::AlignVCenter; if (!username.isEmpty()) { painter->setFont(smaller); painter->drawText(option.rect.adjusted(0, divider, 0, 0), (Qt::AlignLeft | Qt::AlignTop), username); descriptionRect = descriptionRect.adjusted(0, 0, 0, -divider); painter->setFont(option.font); flags &= ~Qt::AlignVCenter; flags |= Qt::AlignBottom; } painter->drawText(descriptionRect, flags, description); } painter->restore(); }
void QToolBarLayout::updateMarginAndSpacing() { QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); if (!tb) return; QStyle *style = tb->style(); QStyleOptionToolBar opt; tb->initStyleOption(&opt); setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb) + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb)); setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb)); }
/*! Renders the delegate using the given \a painter and style \a option for the item specified by \a index. This function paints the item using the view's QStyle. When reimplementing paint in a subclass. Use the initStyleOption() to set up the \a option in the same way as the QStyledItemDelegate. Whenever possible, use the \a option while painting. Especially its \l{QStyleOption::}{rect} variable to decide where to draw and its \l{QStyleOption::}{state} to determine if it is enabled or selected. After painting, you should ensure that the painter is returned to the state it was supplied in when this function was called. For example, it may be useful to call QPainter::save() before painting and QPainter::restore() afterwards. \sa QItemDelegate::paint(), QStyle::drawControl(), QStyle::CE_ItemViewItem */ void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_ASSERT(index.isValid()); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); const QWidget *widget = QStyledItemDelegatePrivate::widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); }
//#---------------------------------------------------------------------------# //#------- PRIVATE -----------------------------------------------------------# //#---------------------------------------------------------------------------# void EditRelationName::initialise() { QStyle* style = QApplication::style(); QIcon icon = style->standardIcon(QStyle::SP_MessageBoxWarning); ui->nameAlert->setPixmap(icon.pixmap(20,20)); QRegExp rx("([A-Za-z\\d\\_]*\\,){100}"); QValidator *validator = new QRegExpValidator(rx, this); ui->nameEdit->setValidator(validator); ui->nameAlert->setVisible(false); }
void AlbumDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QPen oldPen = painter->pen(); QStyle *style = QApplication::style(); int margin = style->pixelMetric(QStyle::PM_ButtonMargin); QRect rect = option.rect; if (option.state & QStyle::State_HasFocus) { painter->fillRect(rect, option.palette.highlight()); painter->setPen(option.palette.color(QPalette::HighlightedText)); } rect.adjust(margin, margin, -margin, -margin); QRect decorationRect = rect; decorationRect.setRight(decorationRect.left() + option.decorationSize.width()); QPixmap decoration = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole)); if (!decoration.isNull()) style->drawItemPixmap(painter, decorationRect, Qt::AlignCenter, decoration); else painter->drawRect(decorationRect); rect.setLeft(decorationRect.right() + margin); QString text = index.data(Qt::DisplayRole).toString(); QRect textRect; painter->drawText(rect, Qt::TextWordWrap, text, &textRect); rect.setTop(textRect.bottom() + margin); text = index.data(Artist).toString(); painter->drawText(rect, Qt::TextWordWrap, text, &textRect); rect.setTop(textRect.bottom() + margin); QVariant trackCount = index.data(TrackCount); if (trackCount.isValid()) { text = trackCount.toInt() != 1 ? tr("%1 Songs").arg(trackCount.toInt()) : tr("1 Song"); painter->drawText(rect, Qt::TextWordWrap, text, &textRect); } painter->setPen(oldPen); }
/*! \reimp */ bool QStyledItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); Q_ASSERT(model); // make sure that the item is checkable Qt::ItemFlags flags = model->flags(index); if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled) || !(flags & Qt::ItemIsEnabled)) return false; // make sure that we have a check state QVariant value = index.data(Qt::CheckStateRole); if (!value.isValid()) return false; const QWidget *widget = QStyledItemDelegatePrivate::widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); // make sure that we have the right event type if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonDblClick) || (event->type() == QEvent::MouseButtonPress)) { QStyleOptionViewItem viewOpt(option); initStyleOption(&viewOpt, index); QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, widget); QMouseEvent *me = static_cast<QMouseEvent*>(event); if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos())) return false; if ((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonDblClick)) return true; } else if (event->type() == QEvent::KeyPress) { if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space && static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select) return false; } else { return false; } Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt()); if (flags & Qt::ItemIsUserTristate) state = ((Qt::CheckState)((state + 1) % 3)); else state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked; return model->setData(index, state, Qt::CheckStateRole); }
// reimplemented virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItemV4 opt(option); opt.showDecorationSelected = true; opt.rect.adjust(0, 0, 0, -1); painter->save(); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); QSize iconSize; #if 0 if (icon.availableSizes().isEmpty()) iconSize = icon.availableSizes().first(); else #endif int s = PsiIconset::instance()->system().iconSize(); iconSize = QSize(s,s); QRect iconRect = opt.rect; iconRect.setLeft(4); iconRect.setWidth(iconSize.width()); icon.paint(painter, iconRect, Qt::AlignCenter, QIcon::Normal, QIcon::On); QRect textRect = opt.rect; textRect.setLeft(iconRect.right() + 8); QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { cg = QPalette::Inactive; } if (option.state & QStyle::State_Selected) { painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); } else { painter->setPen(option.palette.color(cg, QPalette::Text)); } painter->drawText(textRect, index.data(Qt::DisplayRole).toString(), Qt::AlignLeft | Qt::AlignVCenter); drawFocus(painter, option, option.rect); // not opt, because drawFocus() expects normal rect painter->restore(); painter->save(); QPen pen(QColor(0xE0, 0xE0, 0xE0)); QVector<qreal> dashes; dashes << 1.0 << 1.0; pen.setCapStyle(Qt::FlatCap); pen.setDashPattern(dashes); painter->setPen(pen); painter->drawLine(option.rect.left(), option.rect.bottom(), option.rect.right(), option.rect.bottom()); painter->restore(); }
void Appearance::applySettings(SettingsWidget* gui) { const auto mine = dynamic_cast<MySettings*>(gui); const auto name = mine->getStyleName(); current_style_name_ = name; if (current_style_name_ == "Default") return; QStyle* style = QApplication::setStyle(current_style_name_); QApplication::setPalette(style->standardPalette()); }
/*! Returns the size needed by the delegate to display the item specified by \a index, taking into account the style information provided by \a option. This function uses the view's QStyle to determine the size of the item. \sa QStyle::sizeFromContents(), QStyle::CT_ItemViewItem */ QSize QStyledItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QVariant value = index.data(Qt::SizeHintRole); if (value.isValid()) return qvariant_cast<QSize>(value); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); const QWidget *widget = QStyledItemDelegatePrivate::widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget); }
QWidget* DsgnRibbonStatusBarPlugin::createWidget(QWidget* pParent) { QWidget* ptr = new RibbonStatusBar(pParent); #if 0 if (pParent) { QStyle* pStyle = pParent->style(); ptr->setStyle(pStyle); pStyle->polish(ptr); } #endif return ptr; }
QSize ProgressBarDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const { QStyleOptionViewItemV4 opt = option; // initStyleOption( &opt, index ); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); QStyleOptionProgressBar pbOption; pbOption.QStyleOption::operator=( option ); initStyleOptionProgressBar( &pbOption, index ); return style->sizeFromContents( QStyle::CT_ProgressBar, &pbOption, QSize(), opt.widget ); }
void StatusBarLayout::updateMarginAndSpacing() { Statusbar* statusBar = qobject_cast<Statusbar*>( parentWidget() ); if( ! statusBar ) return; QStyle* style = statusBar->style(); QStyleOptionToolBar opt; statusBar->initStyleOption( &opt ); setMargin( style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, statusBar) + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, statusBar) ); setSpacing( style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, statusBar) ); }
void GetAppearance(QApplication *a, AppearanceAttributes *aa) { const char *mName = "GetAppearance: "; // get system default style QStyle *style = a->style(); QString style_class(style->metaObject()->className()); std::string styleName = "windows"; if(style_class == "QWindowsStyle") styleName = "windows"; else if(style_class == "QWindowsVistaStyle") styleName = "windowsvista"; else if(style_class == "QWindowsXPStyle") styleName = "windowsxp"; else if(style_class == "QMotifStyle") styleName = "motif"; else if(style_class == "QCleanlooksStyle") styleName = "cleanlooks"; else if(style_class == "QPlastiqueStyle") styleName = "plastique"; else if(style_class == "QCDEStyle") styleName = "cde"; else if(style_class == "QMacStyle") styleName = "macintosh"; debug1 << mName << "Default System Style is: " << styleName << endl; aa->SetDefaultStyle(styleName); // get system default font QFont font = a->font(); std::string font_name = font.key().toStdString(); debug1 << mName << "Default system font is:" << font_name << endl; aa->SetDefaultFontName(font_name); //set aa colors from defaults QColor bg = a->palette().window().color(); QColor fg = a->palette().windowText().color(); char tmp[20]; SNPRINTF(tmp, 20, "#%02x%02x%02x", bg.red(), bg.green(), bg.blue()); debug1 << mName << "Default background color is:" << tmp << endl; aa->SetDefaultBackground(tmp); SNPRINTF(tmp, 20, "#%02x%02x%02x", fg.red(), fg.green(), fg.blue()); debug1 << mName << "Default foreground color is:" << tmp << endl; aa->SetDefaultForeground(tmp); debug1 << mName << "Default orientation:" << 0 << endl; aa->SetDefaultOrientation(0); }