void StatusBarLayout::updateLayoutStructs() const { if( ! mIsDirty ) return; StatusBarLayout* that = const_cast<StatusBarLayout*>( this ); // const int margin = this->margin(); const int spacing = this->spacing(); QSize sizeHint( 0, 0 ); int visibleCount = 0; for( int i = 0; i < mWidgetList.count(); ++i ) { QWidgetItem* item = mWidgetList.at( i ); if( ! item->isEmpty() ) { const QSize itemSizeHint = item->sizeHint(); sizeHint.rwidth() += (visibleCount == 0 ? 0 : spacing) + itemSizeHint.width(); sizeHint.rheight() = qMax( sizeHint.height(), itemSizeHint.height() ); ++visibleCount; } } // sizeHint += QSize( 2*margin, 2*margin ); that->mIsEmpty = ( visibleCount == 0 ); that->mSizeHint = sizeHint; that->mIsDirty = false; }
void TaskGroup::actionEvent (QActionEvent* e) { QAction *action = e->action(); switch (e->type()) { case QEvent::ActionAdded: { TaskIconLabel *label = new TaskIconLabel( action->icon(), action->text(), this); this->addIconLabel(label); connect(label,SIGNAL(clicked()),action,SIGNAL(triggered())); break; } case QEvent::ActionChanged: { // update label when action changes QBoxLayout* bl = this->groupLayout(); int index = this->actions().indexOf(action); if (index < 0) break; QWidgetItem* item = static_cast<QWidgetItem*>(bl->itemAt(index)); TaskIconLabel* label = static_cast<TaskIconLabel*>(item->widget()); label->setTitle(action->text()); break; } case QEvent::ActionRemoved: { // cannot change anything break; } default: break; } }
void TreeModel::saveNewData(QWidget *widgetContainer, const QModelIndex &parentIndex) { TreeItem *m_parent = itemFromIndex(parentIndex); if (m_parent != NULL) { int totalChilds = m_parent->childCount(); QGridLayout *gridLayout = dynamic_cast<QGridLayout*>(widgetContainer->layout()); for (int i = 0; i < gridLayout->rowCount(); i++) { QWidgetItem *widgetItem = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,3)); if (widgetItem) { QLabel *label = dynamic_cast<QLabel*>(widgetItem->widget()); QWidgetItem *widgetItem2 = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,1)); if (label and widgetItem2) { for (int j = 0; j < totalChilds; j++) { if (label->text() == m_parent->child(j)->getUID()) { QLineEdit *lineEdit = qobject_cast<QLineEdit*>(widgetItem2->widget()); QComboBox *comboBox = qobject_cast<QComboBox*>(widgetItem2->widget()); if (lineEdit) m_parent->child(j)->setValue(lineEdit->text()); else if (comboBox) { QString valAux = ""; if (comboBox->currentText() == "TRUE") valAux = "1"; else if (comboBox->currentText() == "FALSE") valAux = "0"; m_parent->child(j)->setValue(valAux); } TreeItem *item = new TreeItem(m_parent->child(j)); m_parent->removeRow(j); m_parent->insertRow(j, item); } } } } } emit modelModified(); } }
void LayoutDumper::dumpWidgetAndChildren(QDebug& os, const QWidget* w, int level) { QString padding; for (int i = 0; i <= level; i++) { padding += " "; // 4 spaces per level } QLayout* layout = w->layout(); QList<QWidget*> dumped_children; if (layout && !layout->isEmpty()) { os << padding << "Layout: " << getLayoutInfo(layout); QBoxLayout* box_layout = dynamic_cast<QBoxLayout*>(layout); if (box_layout) { os << ", spacing " << box_layout->spacing(); } os << ":\n"; int num_items = layout->count(); for (int i = 0; i < num_items; i++) { QLayoutItem* layout_item = layout->itemAt(i); QString item_info = getLayoutItemInfo(layout_item); if (!item_info.isEmpty()) { os << padding << "- " << item_info << "\n"; } QWidgetItem* wi = dynamic_cast<QWidgetItem*>(layout_item); if (wi && wi->widget()) { dumpWidgetAndChildren(os, wi->widget(), level + 1); dumped_children.push_back(wi->widget()); } } } // now output any child widgets that weren't dumped as part of the layout QList<QWidget*> widgets = w->findChildren<QWidget*>( QString(), Qt::FindDirectChildrenOnly); QList<QWidget*> undumped_children; foreach (QWidget* child, widgets) { if (dumped_children.indexOf(child) == -1) { undumped_children.push_back(child); } } if (!undumped_children.empty()) { os << padding << "Non-layout children:\n"; foreach (QWidget* child, undumped_children) { dumpWidgetAndChildren(os, child, level + 1); }
/*! Inserts \a widget at position \a index, with stretch factor \a stretch and alignment \a alignment. If \a index is negative, the widget is added at the end. The stretch factor applies only in the \l{direction()}{direction} of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more. If the stretch factor is 0 and nothing else in the QBoxLayout has a stretch factor greater than zero, the space is distributed according to the QWidget:sizePolicy() of each widget that's involved. The alignment is specified by \a alignment. The default alignment is 0, which means that the widget fills the entire cell. \sa addWidget(), insertItem() */ void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch, Qt::Alignment alignment) { Q_D(QBoxLayout); if (!checkWidget(this, widget)) return; addChildWidget(widget); if (index < 0) // append index = d->list.count(); QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget); b->setAlignment(alignment); QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch); d->list.insert(index, it); invalidate(); }
void ToolBar::changeIconSizeSub(QLayout* layout, const QSize& iconSize) { int n = layout->count(); for(int i=0; i < n; ++i){ QLayoutItem* item = layout->itemAt(i); QLayout * childLayout = dynamic_cast<QLayout*>(item); if(childLayout){ changeIconSizeSub(childLayout, iconSize); } QWidgetItem* widgetItem = dynamic_cast<QWidgetItem*>(item); if(widgetItem){ QWidget* widget = widgetItem->widget(); ToolButton* button = dynamic_cast<ToolButton*>(widget); if(button){ button->setIconSize(mainWindow->iconSize()); } } } }
static PyObject *meth_QWidgetItem_sizeHint(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf)); { QWidgetItem *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QWidgetItem, &sipCpp)) { QSize *sipRes; Py_BEGIN_ALLOW_THREADS sipRes = new QSize((sipSelfWasArg ? sipCpp->QWidgetItem::sizeHint() : sipCpp->sizeHint())); Py_END_ALLOW_THREADS return sipConvertFromNewType(sipRes,sipType_QSize,NULL); } }
void StatusBarLayout::setGeometry( const QRect& _rect ) { QLayout::setGeometry( _rect ); if( mIsDirty ) updateLayoutStructs(); QRect rect( 0, 0, _rect.width(), _rect.height() ); const int margin = 0;//this->margin(); const int spacing = this->spacing(); int availableWidth = rect.size().width() - 2*margin; const int availableHeight = rect.size().height() - 2*margin; int usedWidth = 0; int visibleCount = 0; int i; for( i = 0; i<mWidgetList.count(); ++i ) { QWidgetItem* item = mWidgetList.at( i ); QWidget* widget = item->widget(); // TODO: is there really no way to get to the geometry data if a widget is hidden? if( widget->isHidden() ) widget->show(); const int itemWidth = item->sizeHint().width(); const int itemSpacing = ( visibleCount == 0 ) ? 0 : spacing; const int newUsedWidth = usedWidth + itemSpacing + itemWidth; // kDebug()<<widget<<<<availableWidth<<usedWidth<<itemWidth<<itemSpacing<<newUsedWidth; const bool isTooWide = ( newUsedWidth > availableWidth ); if( isTooWide ) break; const QPoint pos( margin + usedWidth, margin ); const QSize size( itemWidth, availableHeight ); QRect r( pos, size ); r = QStyle::visualRect( parentWidget()->layoutDirection(), rect, r ); item->setGeometry( r ); usedWidth = newUsedWidth; ++visibleCount; } // hide the rest if needed for( ; i<mWidgetList.count(); ++i ) { QWidgetItem* item = mWidgetList.at( i ); QWidget* widget = item->widget(); if( ! widget->isHidden() ) widget->hide(); } }
QString LayoutDumper::getLayoutItemInfo(QLayoutItem* item) { QWidgetItem* wi = dynamic_cast<QWidgetItem*>(item); QSpacerItem* si = dynamic_cast<QSpacerItem*>(item); if (wi) { if (wi->widget()) { return QString("%1 [alignment: %2]") .arg(getWidgetInfo(*wi->widget())) .arg(toString(wi->alignment())); } } else if (si) { QSize hint = si->sizeHint(); QLayout* layout = si->layout(); return QString("QSpacerItem: sizeHint (%1 x %2), policy %3, " "constraint %4, alignment %5") .arg(hint.width()) .arg(hint.height()) .arg(toString(si->sizePolicy())) .arg(layout ? toString(layout->sizeConstraint()) : "[no layout]") .arg(si->alignment()); } return ""; }