本文整理汇总了C++中QToolBar::iconSize方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolBar::iconSize方法的具体用法?C++ QToolBar::iconSize怎么用?C++ QToolBar::iconSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolBar
的用法示例。
在下文中一共展示了QToolBar::iconSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: QDialog
ToolbarDialog::ToolbarDialog(QWidget* parent)
: QDialog(parent),m_defaultToolBars()
{
setupUi(this);
createDefaultToolBars();
// populate all available actions
QList<QAction*> actions = parent->findChildren<QAction*>(QRegExp("action*"));
QAction* action;
foreach(action, actions) {
if (action->actionGroup()->objectName() != "extraGroup")
continue;
QListWidgetItem* item = new QListWidgetItem(action->toolTip());
item->setIcon(action->icon());
item->setData(Qt::UserRole, QVariant::fromValue((QObject*)action));
listAllActions->addItem(item);
}
// Important to add special Separator
listAllActions->addItem("Separator");
QList<QToolBar*> toolbars = parent->findChildren<QToolBar*>();
QToolBar* toolbar = NULL;
int index = 0;
foreach(toolbar, toolbars) {
index = (int)(toolbar->iconSize().height()/10)-1;
if (toolbar->objectName() != "keyToolBar")
comboToolbars->addItem(toolbar->windowTitle(), QVariant::fromValue((QObject*)toolbar));
}
示例4: addButton
void IconPalette::addButton(QAction * action)
{
actions_.push_back(action);
QToolButton * tb = new QToolButton;
tb->setAutoRaise(true);
tb->setDefaultAction(action);
// trigger tooltip (children of popups do not receive mousemove events)
tb->setMouseTracking(true);
connect(tb, SIGNAL(triggered(QAction *)),
this, SLOT(clicked(QAction *)));
QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget());
connect(toolbar, SIGNAL(iconSizeChanged(const QSize &)),
tb, SLOT(setIconSize(const QSize &)));
tb->setIconSize(toolbar->iconSize());
int const i = actions_.size();
int const ncols = qMin(6, i);
int const row = (i - 1)/ncols + 1;
int const col = qMax(1, i - (row - 1) * 6);
layout_->addWidget(tb, row, col);
}
示例5: iconSize
void tst_QToolBar::iconSize()
{
{
QToolBar tb;
QSignalSpy spy(&tb, SIGNAL(iconSizeChanged(QSize)));
// the default is determined by the style
const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize);
const QSize defaultIconSize = QSize(metric, metric);
const QSize smallIconSize = QSize(metric / 2, metric / 2);
const QSize largeIconSize = QSize(metric * 2, metric * 2);
QCOMPARE(tb.iconSize(), defaultIconSize);
tb.setIconSize(defaultIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(spy.count(), 0);
spy.clear();
tb.setIconSize(largeIconSize);
QCOMPARE(tb.iconSize(), largeIconSize);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.first().first().toSize(), largeIconSize);
// no-op
spy.clear();
tb.setIconSize(largeIconSize);
QCOMPARE(tb.iconSize(), largeIconSize);
QCOMPARE(spy.count(), 0);
spy.clear();
tb.setIconSize(defaultIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.first().first().toSize(), defaultIconSize);
// no-op
spy.clear();
tb.setIconSize(defaultIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(spy.count(), 0);
spy.clear();
tb.setIconSize(smallIconSize);
QCOMPARE(tb.iconSize(), smallIconSize);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.first().first().toSize(), smallIconSize);
// no-op
spy.clear();
tb.setIconSize(smallIconSize);
QCOMPARE(tb.iconSize(), smallIconSize);
QCOMPARE(spy.count(), 0);
// setting the icon size to an invalid QSize will reset the
// iconSize property to the default
tb.setIconSize(QSize());
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(spy.size(), 1);
QCOMPARE(spy.first().first().toSize(), defaultIconSize);
spy.clear();
}
{
QMainWindow mw;
QToolBar tb;
QSignalSpy mwSpy(&mw, SIGNAL(iconSizeChanged(QSize)));
QSignalSpy tbSpy(&tb, SIGNAL(iconSizeChanged(QSize)));
// the default is determined by the style
const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize);
const QSize defaultIconSize = QSize(metric, metric);
const QSize smallIconSize = QSize(metric / 2, metric / 2);
const QSize largeIconSize = QSize(metric * 2, metric * 2);
mw.setIconSize(smallIconSize);
// explicitly set it to the default
tb.setIconSize(defaultIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(tbSpy.count(), 0);
mw.addToolBar(&tb);
// tb icon size should not change since it has been explicitly set
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(tbSpy.count(), 0);
mw.setIconSize(largeIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(tbSpy.count(), 0);
mw.setIconSize(defaultIconSize);
QCOMPARE(tb.iconSize(), defaultIconSize);
QCOMPARE(tbSpy.count(), 0);
mw.setIconSize(smallIconSize);
//.........这里部分代码省略.........
示例6: QToolButton
AccountsToolButton::AccountsToolButton( QWidget* parent )
: QToolButton( parent )
{
m_popup = new AccountsPopupWidget( this );
m_popup->hide();
QToolBar* toolbar = qobject_cast< QToolBar* >( parent );
if ( toolbar )
setIconSize( toolbar->iconSize() );
else
setIconSize( QSize( 22, 22 ) );
//Set up popup...
QWidget *w = new QWidget( this );
w->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
QVBoxLayout *wMainLayout = new QVBoxLayout( w );
w->setLayout( wMainLayout );
TomahawkUtils::unmarginLayout( w->layout() );
w->setContentsMargins( 6, 6, 6, 6 );
#ifdef Q_OS_MAC
w->setContentsMargins( 6, 6, 6, 0 );
wMainLayout->setMargin( 12 );
#endif
m_popup->setWidget( w );
connect( m_popup, SIGNAL( hidden() ), SLOT( popupHidden() ) );
m_model = new Tomahawk::Accounts::AccountModel( this );
m_proxy = new AccountModelFactoryProxy( m_model );
m_proxy->setSourceModel( m_model );
m_proxy->setFilterRowType( Tomahawk::Accounts::AccountModel::TopLevelFactory );
m_proxy->setFilterEnabled( true );
AccountListWidget *view = new AccountListWidget( m_proxy, m_popup );
wMainLayout->addWidget( view );
view->setAutoFillBackground( false );
view->setAttribute( Qt::WA_TranslucentBackground, true );
connect( m_proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( repaint() ) );
QWidget *separatorLine = new QWidget( w );
separatorLine->setFixedHeight( 1 );
separatorLine->setContentsMargins( 0, 0, 0, 0 );
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid " +
TomahawkUtils::Colors::BORDER_LINE.name() + "; }" ); //from ProxyStyle
wMainLayout->addWidget( separatorLine );
wMainLayout->addSpacing( 6 );
QPushButton *settingsButton = new QPushButton( w );
settingsButton->setIcon( QIcon( RESPATH "images/account-settings.png" ) );
settingsButton->setText( tr( "Configure Accounts" ) );
connect( settingsButton, SIGNAL( clicked() ),
window(), SLOT( showSettingsDialog() ) );
QHBoxLayout *bottomLayout = new QHBoxLayout( w );
TomahawkUtils::unmarginLayout( bottomLayout );
bottomLayout->addStretch();
bottomLayout->addWidget( settingsButton );
wMainLayout->addLayout( bottomLayout );
//ToolButton stuff
m_defaultPixmap = QPixmap( RESPATH "images/account-none.png" )
.scaled( iconSize(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation );
connect( m_proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( rowsInserted ( QModelIndex, int, int ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( rowsRemoved( QModelIndex, int, int ) ),
this, SLOT( updateIcons() ) );
connect( m_proxy, SIGNAL( modelReset() ),
this, SLOT( updateIcons() ) );
}