本文整理汇总了C++中QToolBar::toolButtonStyle方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolBar::toolButtonStyle方法的具体用法?C++ QToolBar::toolButtonStyle怎么用?C++ QToolBar::toolButtonStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolBar
的用法示例。
在下文中一共展示了QToolBar::toolButtonStyle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QToolButton
QWidget* ToolAction::createWidget( QWidget *parent )
{
QToolBar *toolBar = qobject_cast< QToolBar * >( parent );
if ( !toolBar )
return 0;
QToolButton *button = new QToolButton( toolBar );
button->setAutoRaise( true );
button->setFocusPolicy( Qt::NoFocus );
button->setIconSize( toolBar->iconSize() );
button->setToolButtonStyle( toolBar->toolButtonStyle() );
button->setPopupMode( QToolButton::DelayedPopup );
button->setMenu( new QMenu( button ) );
button->setCheckable( true );
connect(toolBar, &QToolBar::iconSizeChanged, button, &QToolButton::setIconSize);
connect(toolBar, &QToolBar::toolButtonStyleChanged, button, &QToolButton::setToolButtonStyle);
connect(button, &QToolButton::triggered, toolBar, &QToolBar::actionTriggered);
connect( button->menu(), &QMenu::triggered, this, &ToolAction::slotNewDefaultAction );
m_buttons.append( button );
if ( !m_actions.isEmpty() )
{
button->setDefaultAction( m_actions.first() );
foreach ( QAction *action, m_actions )
{
button->menu()->addAction( action );
if ( action->isChecked() )
button->setDefaultAction( action );
}
示例2: QToolButton
QWidget *KToolBarPopupAction::createWidget(QWidget *_parent)
{
QToolBar *parent = qobject_cast<QToolBar *>(_parent);
if (!parent) {
return QWidgetAction::createWidget(_parent);
}
QToolButton *button = new QToolButton(parent);
button->setAutoRaise(true);
button->setFocusPolicy(Qt::NoFocus);
button->setIconSize(parent->iconSize());
button->setToolButtonStyle(parent->toolButtonStyle());
button->setDefaultAction(this);
connect(parent, &QToolBar::iconSizeChanged,
button, &QAbstractButton::setIconSize);
connect(parent, &QToolBar::toolButtonStyleChanged,
button, &QToolButton::setToolButtonStyle);
connect(button, &QToolButton::triggered,
parent, &QToolBar::actionTriggered);
if (d->delayed)
if (d->stickyMenu) {
button->setPopupMode(QToolButton::MenuButtonPopup);
} else {
button->setPopupMode(QToolButton::DelayedPopup);
}
else {
button->setPopupMode(QToolButton::InstantPopup);
}
return button;
}
示例3: toolButtonStyle
void tst_QToolBar::toolButtonStyle()
{
{
QToolBar tb;
QSignalSpy spy(&tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)));
// no-op
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
tb.setToolButtonStyle(Qt::ToolButtonIconOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(spy.count(), 0);
tb.setToolButtonStyle(Qt::ToolButtonTextOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextOnly);
QCOMPARE(spy.count(), 1);
spy.clear();
// no-op
tb.setToolButtonStyle(Qt::ToolButtonTextOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextOnly);
QCOMPARE(spy.count(), 0);
tb.setToolButtonStyle(Qt::ToolButtonIconOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(spy.count(), 1);
spy.clear();
// no-op
tb.setToolButtonStyle(Qt::ToolButtonIconOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(spy.count(), 0);
tb.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextBesideIcon);
QCOMPARE(spy.count(), 1);
spy.clear();
// no-op
tb.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextBesideIcon);
QCOMPARE(spy.count(), 0);
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextUnderIcon);
QCOMPARE(spy.count(), 1);
spy.clear();
// no-op
tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonTextUnderIcon);
QCOMPARE(spy.count(), 0);
tb.setToolButtonStyle(Qt::ToolButtonFollowStyle);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonFollowStyle);
QCOMPARE(spy.count(), 1);
}
{
QMainWindow mw;
QToolBar tb;
QSignalSpy mwSpy(&mw, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)));
QSignalSpy tbSpy(&tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)));
mw.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
// explicitly set the tb to the default
tb.setToolButtonStyle(Qt::ToolButtonIconOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(tbSpy.count(), 0);
mw.addToolBar(&tb);
// tb icon size should not change since it has been explicitly set
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(tbSpy.count(), 0);
mw.setToolButtonStyle(Qt::ToolButtonIconOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(tbSpy.count(), 0);
mw.setToolButtonStyle(Qt::ToolButtonTextOnly);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(tbSpy.count(), 0);
mw.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QCOMPARE(tb.toolButtonStyle(), Qt::ToolButtonIconOnly);
QCOMPARE(tbSpy.count(), 0);
// note: there is no way to clear the explicitly set tool
// button style... once you explicitly set it, the toolbar
// will never follow the mainwindow again
}
}