本文整理汇总了C++中QToolBar::orientation方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolBar::orientation方法的具体用法?C++ QToolBar::orientation怎么用?C++ QToolBar::orientation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolBar
的用法示例。
在下文中一共展示了QToolBar::orientation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showEvent
void IconPalette::showEvent(QShowEvent * /*event*/)
{
resize(sizeHint());
setMaximumSize(sizeHint());
int hoffset = - parentWidget()->pos().x();
int voffset = - parentWidget()->pos().y();
int const parwidth = parentWidget()->geometry().width();
int const parheight = parentWidget()->geometry().height();
// vertical toolbar?
QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
if (toolbar && toolbar->orientation() == Qt::Vertical) {
hoffset += parwidth;
voffset -= parheight;
}
QRect const screen = qApp->desktop()->availableGeometry(this);
QPoint const gpos = parentWidget()->mapToGlobal(
parentWidget()->geometry().bottomLeft());
// space to the right?
if (gpos.x() + hoffset + width() > screen.width()) {
hoffset -= width();
if (toolbar && toolbar->orientation() == Qt::Vertical)
hoffset -= parwidth;
else
hoffset += parwidth;
}
// space at the bottom?
if (gpos.y() + voffset + height() > screen.height()) {
voffset -= height();
if (toolbar && toolbar->orientation() == Qt::Horizontal)
voffset -= parheight;
else
voffset += parheight;
}
QRect r = rect();
r.moveTo(gpos.x() + hoffset, gpos.y() + voffset);
setGeometry(r);
}
示例2: addTo
bool QSeparatorAction::addTo( QWidget *w )
{
if ( ::qt_cast<QToolBar*>(w) ) {
QToolBar *tb = (QToolBar*)w;
wid = new QDesignerToolBarSeparator( tb->orientation(), tb );
return TRUE;
} else if ( ::qt_cast<QPopupMenu*>(w) ) {
idx = ( (QPopupMenu*)w )->count();
( (QPopupMenu*)w )->insertSeparator( idx );
return TRUE;
}
return FALSE;
}
示例3: _q_popupPressed
void QPushButtonPrivate::_q_popupPressed()
{
Q_Q(QPushButton);
if (!down || !menu)
return;
menu->setNoReplayFor(q);
bool horizontal = true;
#if !defined(QT_NO_TOOLBAR)
QToolBar *tb = qobject_cast<QToolBar*>(q->parentWidget());
if (tb && tb->orientation() == Qt::Vertical)
horizontal = false;
#endif
QWidgetItem item(q);
QRect rect = item.geometry();
rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height());
QSize menuSize = menu->sizeHint();
QPoint globalPos = q->mapToGlobal(rect.topLeft());
int x = globalPos.x();
int y = globalPos.y();
if (horizontal) {
if (globalPos.y() + rect.height() + menuSize.height() <= qApp->desktop()->height()) {
y += rect.height();
} else {
y -= menuSize.height();
}
if (q->layoutDirection() == Qt::RightToLeft)
x += rect.width() - menuSize.width();
} else {
if (globalPos.x() + rect.width() + menu->sizeHint().width() <= qApp->desktop()->width())
x += rect.width();
else
x -= menuSize.width();
}
QPointer<QPushButton> guard(q);
//Because of a delay in menu effects, we must keep track of the
//menu visibility to avoid flicker on button release
menuOpen = true;
menu->exec(QPoint(x, y));
if (guard) {
menuOpen = false;
q->setDown(false);
}
}
示例4: adjustedMenuPosition
QPoint QPushButtonPrivate::adjustedMenuPosition()
{
Q_Q(QPushButton);
bool horizontal = true;
#if !defined(QT_NO_TOOLBAR)
QToolBar *tb = qobject_cast<QToolBar*>(parent);
if (tb && tb->orientation() == Qt::Vertical)
horizontal = false;
#endif
QWidgetItem item(q);
QRect rect = item.geometry();
rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height());
QSize menuSize = menu->sizeHint();
QPoint globalPos = q->mapToGlobal(rect.topLeft());
int x = globalPos.x();
int y = globalPos.y();
if (horizontal) {
if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()) {
y += rect.height();
} else {
y -= menuSize.height();
}
if (q->layoutDirection() == Qt::RightToLeft)
x += rect.width() - menuSize.width();
} else {
if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width())
x += rect.width();
else
x -= menuSize.width();
}
return QPoint(x,y);
}
示例5: orientation
void tst_QToolBar::orientation()
{
QToolBar tb;
QCOMPARE(tb.orientation(), Qt::Horizontal);
QSignalSpy spy(&tb, SIGNAL(orientationChanged(Qt::Orientation)));
tb.setOrientation(Qt::Vertical);
QCOMPARE(tb.orientation(), Qt::Vertical);
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()),
tb.orientation());
spy.clear();
tb.setOrientation(tb.orientation());
QCOMPARE(spy.count(), 0);
tb.setOrientation(Qt::Horizontal);
QCOMPARE(tb.orientation(), Qt::Horizontal);
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()),
tb.orientation());
spy.clear();
tb.setOrientation(tb.orientation());
QCOMPARE(spy.count(), 0);
tb.setOrientation(Qt::Vertical);
QCOMPARE(tb.orientation(), Qt::Vertical);
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()),
tb.orientation());
spy.clear();
tb.setOrientation(tb.orientation());
QCOMPARE(spy.count(), 0);
tb.setOrientation(Qt::Horizontal);
QCOMPARE(tb.orientation(), Qt::Horizontal);
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()),
tb.orientation());
spy.clear();
tb.setOrientation(tb.orientation());
QCOMPARE(spy.count(), 0);
tb.setOrientation(Qt::Vertical);
QCOMPARE(tb.orientation(), Qt::Vertical);
QCOMPARE(spy.count(), 1);
QCOMPARE(*static_cast<const Qt::Orientation *>(spy.at(0).value(0).constData()),
tb.orientation());
spy.clear();
tb.setOrientation(tb.orientation());
QCOMPARE(spy.count(), 0);
}
示例6: drawComplexControl
void WindowsModernStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex* option,
QPainter* painter, const QWidget* widget ) const
{
switch ( control ) {
case CC_ToolButton: {
QToolBar* toolBar;
if ( widget && ( toolBar = qobject_cast<QToolBar*>( widget->parentWidget() ) ) ) {
if ( const QStyleOptionToolButton* optionToolButton = qstyleoption_cast<const QStyleOptionToolButton*>( option ) ) {
QRect buttonRect = subControlRect( control, option, SC_ToolButton, widget );
QStyle::State buttonState = option->state & ~State_Sunken;
if ( option->state & State_Sunken ) {
if ( optionToolButton->activeSubControls & SC_ToolButton )
buttonState |= State_Sunken;
else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
buttonState |= State_MouseOver;
}
bool selected = buttonState & State_MouseOver && option->state & State_Enabled;
bool checked = buttonState & State_On;
bool sunken = buttonState & State_Sunken;
if ( selected || checked || sunken ) {
QRect rect = buttonRect.adjusted( 0, 0, -1, -1 );
painter->setPen( m_colorItemBorder );
QLinearGradient gradient;
if ( toolBar->orientation() == Qt::Vertical )
gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
else
gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
if ( sunken || (selected && checked) ) {
gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
gradient.setColorAt( 0.5, m_colorItemSunkenMiddle );
gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
} else if ( checked ) {
gradient.setColorAt( 0.0, m_colorItemCheckedBegin );
gradient.setColorAt( 0.5, m_colorItemCheckedMiddle );
gradient.setColorAt( 1.0, m_colorItemCheckedEnd );
} else {
gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
gradient.setColorAt( 0.5, m_colorItemBackgroundMiddle );
gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
}
painter->setBrush( gradient );
painter->drawRect( rect );
}
QStyleOptionToolButton optionLabel = *optionToolButton;
int fw = pixelMetric( PM_DefaultFrameWidth, option, widget );
optionLabel.rect = buttonRect.adjusted( fw, fw, -fw, -fw );
drawControl( CE_ToolButtonLabel, &optionLabel, painter, widget );
if ( optionToolButton->subControls & SC_ToolButtonMenu ) {
QStyleOption optionMenu = *optionToolButton;
optionMenu.rect = subControlRect( control, option, SC_ToolButtonMenu, widget );
optionMenu.state = optionToolButton->state & ~State_Sunken;
if ( optionToolButton->state & State_Sunken ) {
if ( optionToolButton->activeSubControls & SC_ToolButton )
optionMenu.state |= State_MouseOver | State_Sunken;
else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
optionMenu.state |= State_Sunken;
}
drawPrimitive( PE_IndicatorButtonDropDown, &optionMenu, painter, widget );
} else if ( optionToolButton->features & QStyleOptionToolButton::HasMenu ) {
int size = pixelMetric( PM_MenuButtonIndicator, option, widget );
QRect rect = optionToolButton->rect;
QStyleOptionToolButton optionArrow = *optionToolButton;
optionArrow.rect = QRect( rect.right() + 4 - size, rect.height() - size + 4, size - 5, size - 5 );
drawPrimitive( PE_IndicatorArrowDown, &optionArrow, painter, widget );
}
return;
}
}
break;
}
default:
break;
}
if ( useVista() )
QWindowsVistaStyle::drawComplexControl( control, option, painter, widget );
else
QWindowsXPStyle::drawComplexControl( control, option, painter, widget );
}
示例7: drawPrimitive
void WindowsModernStyle::drawPrimitive( PrimitiveElement element, const QStyleOption* option,
QPainter* painter, const QWidget* widget ) const
{
switch ( element ) {
case PE_Widget:
if ( qobject_cast<const QMainWindow*>( widget ) ) {
QRect rect = option->rect;
if ( QStatusBar* statusBar = widget->findChild<QStatusBar*>() ) {
rect.adjust( 0, 0, 0, -statusBar->height() );
painter->setPen( option->palette.light().color() );
painter->drawLine( rect.bottomLeft() + QPoint( 0, 1 ),
rect.bottomRight() + QPoint( 0, 1 ) );
}
QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
gradient.setColorAt( 0.0, m_colorBackgroundBegin );
gradient.setColorAt( 0.6, m_colorBackgroundEnd );
painter->fillRect( rect, gradient );
return;
}
if ( qobject_cast<const QToolBox*>( widget ) ) {
QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
gradient.setColorAt( 0.4, m_colorBackgroundBegin );
gradient.setColorAt( 1.0, m_colorBackgroundEnd );
painter->fillRect( option->rect, gradient );
return;
}
if ( isToolBoxPanel( widget ) ) {
QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
gradient.setColorAt( 0.4, m_colorBarMiddle );
gradient.setColorAt( 1.0, m_colorBarBegin );
painter->fillRect( option->rect, gradient );
return;
}
break;
case PE_WindowGradient: {
QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
gradient.setColorAt( 0.0, m_colorBackgroundBegin );
gradient.setColorAt( 0.6, m_colorBackgroundEnd );
painter->fillRect( option->rect, gradient );
return;
}
case PE_PanelMenuBar:
return;
case PE_FrameMenu:
painter->setPen( m_colorMenuBorder );
painter->setBrush( Qt::NoBrush );
painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
if ( const QMenu* menu = qobject_cast<const QMenu*>( widget ) ) {
if ( const QMenuBar* menuBar = qobject_cast<const QMenuBar*>( menu->parent() ) ) {
QRect rect = menuBar->actionGeometry( menu->menuAction() );
if ( !rect.isEmpty() ) {
painter->setPen( m_colorMenuBackground );
painter->drawLine( 1, 0, rect.width() - 2, 0 );
}
}
}
if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
QRect rect = option->rect.adjusted( 1, 1, -1, -1 );
QLinearGradient gradient;
if ( toolBar->orientation() == Qt::Vertical )
gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
else
gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
gradient.setColorAt( 0.0, m_colorBarBegin );
gradient.setColorAt( 0.4, m_colorBarMiddle );
gradient.setColorAt( 0.6, m_colorBarMiddle );
gradient.setColorAt( 1.0, m_colorBarEnd );
painter->fillRect( rect, gradient );
}
return;
case PE_IndicatorToolBarHandle:
if ( option->state & State_Horizontal ) {
for ( int i = option->rect.height() / 5; i <= 4 * ( option->rect.height() / 5 ); i += 5 ) {
int x = option->rect.left() + 3;
int y = option->rect.top() + i + 1;
painter->fillRect( x + 1, y, 2, 2, m_colorHandleLight );
painter->fillRect( x, y - 1, 2, 2, m_colorHandle );
}
} else {
for ( int i = option->rect.width() / 5; i <= 4 * ( option->rect.width() / 5 ); i += 5 ) {
int x = option->rect.left() + i + 1;
int y = option->rect.top() + 3;
painter->fillRect( x, y + 1, 2, 2, m_colorHandleLight );
painter->fillRect( x - 1, y, 2, 2, m_colorHandle );
}
}
return;
case PE_IndicatorToolBarSeparator:
painter->setPen( m_colorSeparator );
if ( option->state & State_Horizontal )
painter->drawLine( ( option->rect.left() + option->rect.right() - 1 ) / 2, option->rect.top() + 2,
//.........这里部分代码省略.........
示例8: popupTimerDone
void QToolButtonPrivate::popupTimerDone()
{
Q_Q(QToolButton);
popupTimer.stop();
if (!menuButtonDown && !down)
return;
menuButtonDown = true;
QPointer<QMenu> actualMenu;
bool mustDeleteActualMenu = false;
if(menuAction) {
actualMenu = menuAction->menu();
} else if (defaultAction && defaultAction->menu()) {
actualMenu = defaultAction->menu();
} else {
actualMenu = new QMenu(q);
mustDeleteActualMenu = true;
for(int i = 0; i < actions.size(); i++)
actualMenu->addAction(actions.at(i));
}
repeat = q->autoRepeat();
q->setAutoRepeat(false);
bool horizontal = true;
#if !defined(QT_NO_TOOLBAR)
QToolBar *tb = qobject_cast<QToolBar*>(parent);
if (tb && tb->orientation() == Qt::Vertical)
horizontal = false;
#endif
QPoint p;
QRect screen = QApplication::desktop()->availableGeometry(q);
QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint();
QRect rect = q->rect();
if (horizontal) {
if (q->isRightToLeft()) {
if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
p = q->mapToGlobal(rect.bottomRight());
} else {
p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
}
p.rx() -= sh.width();
} else {
if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
p = q->mapToGlobal(rect.bottomLeft());
} else {
p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
}
}
} else {
if (q->isRightToLeft()) {
if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) {
p = q->mapToGlobal(rect.topRight());
} else {
p = q->mapToGlobal(rect.topLeft());
p.rx() -= sh.width();
}
} else {
if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) {
p = q->mapToGlobal(rect.topRight());
} else {
p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0));
}
}
}
p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
p.ry() += 1;
QPointer<QToolButton> that = q;
actualMenu->setNoReplayFor(q);
if (!mustDeleteActualMenu) //only if action are not in this widget
QObject::connect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
actualMenu->d_func()->causedPopup.widget = q;
actualMenu->d_func()->causedPopup.action = defaultAction;
actionsCopy = q->actions(); //(the list of action may be modified in slots)
actualMenu->exec(p);
QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown()));
if (mustDeleteActualMenu)
delete actualMenu;
else
QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*)));
if (!that)
return;
actionsCopy.clear();
if (repeat)
q->setAutoRepeat(true);
}