本文整理汇总了C++中QWidgetAction::requestWidget方法的典型用法代码示例。如果您正苦于以下问题:C++ QWidgetAction::requestWidget方法的具体用法?C++ QWidgetAction::requestWidget怎么用?C++ QWidgetAction::requestWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWidgetAction
的用法示例。
在下文中一共展示了QWidgetAction::requestWidget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
QWidget* GCF::ActionContainerWidget::createWidget(QAction* action, int rowSpan, int colSpan)
{
QWidget* ret = 0;
int gSize=int((fontMetrics().height()+fontMetrics().ascent())*1.2);
int minWidth = gSize*colSpan;
QWidgetAction* wAction = qobject_cast<QWidgetAction*>(action);
if(wAction)
ret = wAction->requestWidget(this);
else
{
QToolButton* tb = new QToolButton(this);
tb->setDefaultAction(action);
tb->setAutoRaise(true);
/*if(action->menu())
tb->setMenu(action->menu());*/
tb->setIconSize(QSize(gSize-4,gSize-4));
if(action->icon().isNull())
tb->setToolButtonStyle(Qt::ToolButtonTextOnly);
else if(colSpan == rowSpan && colSpan >= 2)
tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
else if(colSpan == rowSpan && colSpan == 1)
tb->setToolButtonStyle(Qt::ToolButtonIconOnly);
else if(colSpan >= 2 || rowSpan == 1)
tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
else if(rowSpan >= 3)
tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
int mw = 0;
if(tb->toolButtonStyle() != Qt::ToolButtonIconOnly)
mw += fontMetrics().width(action->iconText())+2*fontMetrics().width("_");
if(!action->icon().isNull())
{
switch(tb->toolButtonStyle())
{
case Qt::ToolButtonTextUnderIcon:
if(mw < gSize-4)
mw = gSize-4;
break;
case Qt::ToolButtonTextBesideIcon:
mw += gSize-4;
break;
}
}
if(minWidth < mw)
minWidth = mw;
if(action->menu())
{
// Connect the default action object to the tool button. This way
// when the toolbutton with menu is clicked, the default action is
// shown.
QList<QAction*> actions = action->menu()->actions();
QAction* defAction = 0;
for(int i=0; i<actions.count(); i++)
{
QAction* action = actions[i];
QList<QByteArray> propNames = action->dynamicPropertyNames();
if(propNames.contains("_default_"))
{
bool val = action->property("_default_").toBool();
if(val)
{
defAction = action;
break;
}
}
}
if(defAction)
{
if(defAction->isCheckable())
connect(tb, SIGNAL(clicked()), defAction, SLOT(toggle()));
else
connect(tb, SIGNAL(clicked()), defAction, SLOT(trigger()));
QFont font = defAction->font();
font.setBold(true);
defAction->setFont(font);
}
}
ret = tb;
}
ret->setMinimumSize(minWidth, gSize*rowSpan);
if(!action->icon().isNull())
{
QFont font = ret->font();
// font.setPointSize(font.pointSize()-1);
ret->setFont(font);
}
/*static QPlastiqueStyle Style;
ret->setStyle(&Style);*/
return ret;
//.........这里部分代码省略.........