本文整理汇总了C++中QStyleOptionComboBox::initFrom方法的典型用法代码示例。如果您正苦于以下问题:C++ QStyleOptionComboBox::initFrom方法的具体用法?C++ QStyleOptionComboBox::initFrom怎么用?C++ QStyleOptionComboBox::initFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStyleOptionComboBox
的用法示例。
在下文中一共展示了QStyleOptionComboBox::initFrom方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void KexiDBComboBox::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.setPen(palette().color(QPalette::Text));
// QColorGroup cg(palette().active());
// if ( hasFocus() )
// cg.setColor(QColorGroup::Base, cg.highlight());
// else
QPalette pal(palette());
pal.setColor(QColorGroup::Base, paletteBackgroundColor()); //update base color using (reimplemented) bg color
if (width() < 5 || height() < 5) {
qDrawShadePanel(&p, rect(), pal, false /* !sunken */,
2 /*line width*/, &pal.brush(QPalette::Button)/*fill*/);
return;
}
#ifdef __GNUC__
#warning TODO KexiDBComboBox::paintEvent()
#else
#pragma WARNING( TODO KexiDBComboBox::paintEvent() )
#endif
QStyleOptionComboBox option;
option.palette = pal;
option.initFrom(d->paintedCombo);
if (isEnabled())
option.state |= QStyle::State_Enabled;
if (hasFocus())
option.state |= QStyle::State_HasFocus;
if (d->mouseOver)
option.state |= QStyle::State_MouseOver;
style()->drawComplexControl(QStyle::CC_ComboBox, &option, &p, d->paintedCombo);
#if 0 //TODO
//! @todo support reverse layout
//bool reverse = QApplication::reverseLayout();
style()->drawComplexControl(QStyle::CC_ComboBox, &option, &p, d->paintedCombo /*this*/
flags, (uint)QStyle::SC_All,
(d->buttonPressed ? QStyle::SC_ComboBoxArrow : QStyle::SC_None)
);
if (d->isEditable) {
//if editable, editor paints itself, nothing to do
} else { //not editable: we need to paint the current item
QRect editorGeometry(this->editorGeometry());
if (hasFocus()) {
if (0 == qstrcmp(style()->name(), "windows")) //a hack
p.fillRect(editorGeometry, cg.brush(QColorGroup::Highlight));
QRect r(QStyle::visualRect(style()->subRect(QStyle::SR_ComboBoxFocusRect, d->paintedCombo), this));
r = QRect(r.left() - 1, r.top() - 1, r.width() + 2, r.height() + 2); //enlare by 1 pixel each side to avoid covering by the subwidget
style()->drawPrimitive(QStyle::PE_FocusRect, &p,
r, cg, flags | QStyle::Style_FocusAtBorder, QStyleOption(cg.highlight()));
}
//todo
}
#endif
}
示例2: createEditor
void KexiDBComboBox::createEditor()
{
KexiDBAutoField::createEditor();
if (subwidget()) {
subwidget()->setGeometry(editorGeometry());
if (!d->isEditable) {
QStyleOptionComboBox option;
option.initFrom(subwidget());
const QRect comboRect = subwidget()->style()->subControlRect(
QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, subwidget());
kDebug() << "comboRect:" << comboRect;
subwidget()->setContentsMargins(comboRect.left(), comboRect.top(),
width() - comboRect.right(), height() - comboRect.bottom());
int l, t, r, b;
subwidget()->getContentsMargins(&l, &t, &r, &b);
kDebug() << "altered margins:" << l << t << r << b;
subwidget()->setFocusPolicy(Qt::NoFocus);
subwidget()->setCursor(QCursor(Qt::ArrowCursor)); // widgets like listedit have IbeamCursor, we don't want that
QPalette subwidgetPalette(subwidget()->palette());
subwidgetPalette.setColor(QColorGroup::Base, Qt::transparent);
subwidget()->setPalette(subwidgetPalette);
d->subWidgetsWithDisabledEvents.clear();
d->subWidgetsWithDisabledEvents << subwidget();
subwidget()->installEventFilter(this);
QList<QWidget*> widgets(subwidget()->findChildren<QWidget*>());
foreach(QWidget *widget, widgets) {
d->subWidgetsWithDisabledEvents << widget;
widget->installEventFilter(this);
}
}
示例3: mousePressEvent
void KonqCombo::mousePressEvent( QMouseEvent *e )
{
m_dragStart = QPoint(); // null QPoint
if ( e->button() == Qt::LeftButton && !itemIcon( currentIndex()).isNull() ) {
// check if the pixmap was clicked
int x = e->pos().x();
QStyleOptionComboBox comboOpt;
getStyleOption(&comboOpt);
int x0 = QStyle::visualRect( layoutDirection(), rect(),
style()->subControlRect( QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxEditField,
this ) ).x();
if ( x > x0 + 2 && x < lineEdit()->x() ) {
m_dragStart = e->pos();
return; // don't call KComboBox::mousePressEvent!
}
}
QStyleOptionComboBox optCombo;
optCombo.initFrom(this);
if ( e->button() == Qt::LeftButton && m_pageSecurity != KonqMainWindow::NotCrypted &&
style()->subElementRect( QStyle::SE_ComboBoxFocusRect, &optCombo, this ).contains( e->pos() ) )
emit showPageSecurity();
KComboBox::mousePressEvent( e );
}
示例4: paintEvent
void QmitkComboBoxListView::paintEvent(QPaintEvent *event)
{
if (m_ComboBox != NULL)
{
QStyleOptionComboBox option;
option.initFrom(m_ComboBox);
option.editable = m_ComboBox->isEditable();
if (m_ComboBox->style()->styleHint(QStyle::SH_ComboBox_Popup, &option, m_ComboBox))
{
QStyleOptionMenuItem menuOption;
menuOption.initFrom(this);
menuOption.palette = this->palette();
menuOption.state = QStyle::State_None;
menuOption.checkType = QStyleOptionMenuItem::NotCheckable;
menuOption.menuRect = event->rect();
menuOption.maxIconWidth = 0;
menuOption.tabWidth = 0;
QPainter painter(this->viewport());
m_ComboBox->style()->drawControl(QStyle::CE_MenuEmptyArea, &menuOption, &painter, this);
}
}
QListView::paintEvent(event);
}
示例5: paintEvent
void ActionComboBoxWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
QStyleOptionComboBox comboBoxOption;
comboBoxOption.initFrom(this);
comboBoxOption.editable = false;
style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, &painter, this);
QStyleOptionViewItem viewItemOption;
viewItemOption.initFrom(this);
viewItemOption.displayAlignment |= Qt::AlignVCenter;
if (currentIndex() >= 0)
{
itemDelegate()->paint(&painter, viewItemOption, m_view->getModel()->index(currentIndex(), 0));
}
else
{
const int textMargin = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, this) + 1);
painter.setFont(viewItemOption.font);
painter.drawText(viewItemOption.rect.adjusted(textMargin, 0, -textMargin, 0), Qt::AlignVCenter, tr("Select Action"));
}
}
示例6: paintEvent
void StatusChangeButton::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
if(underMouse()) {
QStyleOptionButton opt;
opt.initFrom(this);
if(isDown()) {
opt.state |= QStyle::State_Sunken;
}
painter.drawControl(QStyle::CE_PushButton, opt);
}
painter.setPen(palette().color(QPalette::Text));
QRect textRect = rect();
textRect.moveLeft(iconSize().width() + 4);
painter.drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, text());
painter.drawPixmap(QPoint(2, (height() - iconSize().height()) / 2), icon().pixmap(iconSize()));
QStyleOptionComboBox opt;
opt.initFrom(this);
opt.rect = QRect(width() - 15, height() / 2 - 6, 11, 13);
painter.drawPrimitive(QStyle::PE_IndicatorArrowDown, opt);
}
示例7: QComboBox
FlagBox::FlagBox(QWidget *parent)
: QComboBox(parent)
{
m_model = new FlagBoxModel(this);
setModel(m_model);
QStyleOptionComboBox opt;
opt.initFrom(this);
opt.editable = isEditable();
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this))
setItemDelegate(new QItemDelegate(this));
connect(this, SIGNAL(activated(int)), this, SLOT(slotActivated(int)));
}
示例8: sizeHint
QSize SqueezedComboBox::sizeHint() const
{
ensurePolished();
QFontMetrics fm = fontMetrics();
int maxW = count() ? 18 : 7 * fm.width(QChar('x')) + 18;
int maxH = qMax(fm.lineSpacing(), 14) + 2;
QStyleOptionComboBox options;
options.initFrom(this);
return style()->sizeFromContents(QStyle::CT_ComboBox, &options,
QSize(maxW, maxH), this).expandedTo(QApplication::globalStrut());
}
示例9: registerPerspective
void DebuggerMainWindow::registerPerspective(const QByteArray &perspectiveId, const Perspective &perspective)
{
m_perspectiveForPerspectiveId.insert(perspectiveId, perspective);
m_perspectiveChooser->addItem(perspective.name(), perspectiveId);
// adjust width if necessary
const int oldWidth = m_perspectiveChooser->width();
const int contentWidth = m_perspectiveChooser->fontMetrics().width(perspective.name());
QStyleOptionComboBox option;
option.initFrom(m_perspectiveChooser);
const QSize sz(contentWidth, 1);
const int width = m_perspectiveChooser->style()->sizeFromContents(
QStyle::CT_ComboBox, &option, sz).width();
if (width > oldWidth)
m_perspectiveChooser->setFixedWidth(width);
}
示例10: paintMenuListButton
bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i,
const IntRect& r)
{
StylePainter p(i);
if (!p.isValid())
return true;
QStyleOptionComboBox option;
if (p.widget)
option.initFrom(p.widget);
applyTheme(option, o);
option.rect = r;
// for drawing the combo box arrow, rely only on the fallback style
p.style = fallbackStyle();
option.subControls = QStyle::SC_ComboBoxArrow;
p.drawComplexControl(QStyle::CC_ComboBox, option);
return false;
}
示例11: paintEvent
void StatusArrowButton::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
if(underMouse()) {
QStyleOptionButton opt;
opt.initFrom(this);
if(isDown()) {
opt.state |= QStyle::State_Sunken;
}
painter.drawControl(QStyle::CE_PushButton, opt);
}
QStyleOptionComboBox opt;
opt.initFrom(this);
opt.rect = QRect(width() - 15, height() / 2 - 6, 11, 13);
painter.drawPrimitive(QStyle::PE_IndicatorArrowDown, opt);
}
示例12: paintMenuList
bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
QStyle* style = 0;
QPainter* painter = 0;
QWidget* widget = 0;
if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget))
return true;
QStyleOptionComboBox opt;
opt.initFrom(widget);
EAppearance appearance = applyTheme(opt, o);
const QPoint topLeft = r.topLeft();
painter->translate(topLeft);
opt.rect.moveTo(QPoint(0,0));
opt.rect.setSize(r.size());
opt.frame = false;
style->drawComplexControl(QStyle::CC_ComboBox, &opt, painter, widget);
painter->translate(-topLeft);
return false;
}
示例13: fm
VBoxOSTypeSelectorWidget::VBoxOSTypeSelectorWidget (QWidget *aParent)
: QIWithRetranslateUI <QWidget> (aParent)
, mTxFamilyName (new QLabel (this))
, mTxTypeName (new QLabel (this))
, mPxTypeIcon (new QLabel (this))
, mCbFamily (new QComboBox (this))
, mCbType (new QComboBox (this))
, mLayoutPosition (-1)
, mLayoutActivated (false)
{
/* Register CGuestOSType type */
qRegisterMetaType<CGuestOSType>();
/* Setup widgets */
mTxFamilyName->setAlignment (Qt::AlignRight);
mTxTypeName->setAlignment (Qt::AlignRight);
mTxFamilyName->setBuddy (mCbFamily);
mTxTypeName->setBuddy (mCbType);
mTxFamilyName->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed);
mTxTypeName->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed);
mCbFamily->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
mCbType->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
mPxTypeIcon->setFixedSize (32, 32);
/* Check if host supports (AMD-V or VT-x) and long mode */
CHost host = vboxGlobal().host();
m_fSupportsHWVirtEx = host.GetProcessorFeature(KProcessorFeature_HWVirtEx);
m_fSupportsLongMode = host.GetProcessorFeature(KProcessorFeature_LongMode);
/* Fill OS family selector */
int maximumSize = 0;
QFontMetrics fm (mCbFamily->font());
QList <CGuestOSType> families (vboxGlobal().vmGuestOSFamilyList());
for (int i = 0; i < families.size(); ++ i)
{
/* Search for maximum length among family names */
QString familyName (families [i].GetFamilyDescription());
maximumSize = maximumSize < fm.width (familyName) ?
fm.width (familyName) : maximumSize;
mCbFamily->insertItem (i, familyName);
mCbFamily->setItemData (i, families [i].GetFamilyId(), RoleTypeID);
/* Search for maximum length among type names */
QList <CGuestOSType> types (vboxGlobal().vmGuestOSTypeList (families [i].GetFamilyId()));
for (int j = 0; j < types.size(); ++ j)
{
QString typeName (types [j].GetDescription());
maximumSize = maximumSize < fm.width (typeName) ?
fm.width (typeName) : maximumSize;
}
}
mCbFamily->setCurrentIndex (0);
onFamilyChanged (mCbFamily->currentIndex());
/* Set the minimum size for OS Type & Family selectors. */
QStyleOptionComboBox options;
options.initFrom (mCbFamily);
QSize size (style()->sizeFromContents (QStyle::CT_ComboBox, &options,
QSize (maximumSize, fm.height()), mCbFamily));
mCbFamily->setMinimumWidth (size.width());
mCbType->setMinimumWidth (size.width());
/* Slots connections */
connect (mCbFamily, SIGNAL (currentIndexChanged (int)),
this, SLOT (onFamilyChanged (int)));
connect (mCbType, SIGNAL (currentIndexChanged (int)),
this, SLOT (onTypeChanged (int)));
/* Retranslate */
retranslateUi();
}