void layoutOperations::insertLayoutItem( int Index, QWidget *Widget, QLayoutItem *Item, int Stretch ) { if ( Widget == NULL ) return; QBoxLayout *Layout = dynamic_cast<QBoxLayout*>( Widget->layout() ); if ( Layout == NULL ) return; do { QWidget *ItemWidget = Item->widget(); if ( ItemWidget != NULL ) { Layout->insertWidget( Index, ItemWidget, Stretch ); break; } QLayout *ItemLayout = Item->layout(); if ( ItemLayout != NULL ) { Layout->insertLayout( Index, ItemLayout, Stretch ); break; } QSpacerItem *ItemSpace = Item->spacerItem(); if ( ItemSpace != NULL ) { Layout->insertSpacerItem( Index, ItemSpace ); break; } } while ( false ); }
void RatingWidget::leaveEvent(QEvent* event_) { Q_UNUSED(event_); setUpdatesEnabled(false); m_clearButton->hide(); QBoxLayout* l = ::qobject_cast<QBoxLayout*>(layout()); l->insertSpacerItem(m_total+1, m_clearSpacer); setUpdatesEnabled(true); }
void tst_QBoxLayout::insertSpacerItem() { QWidget *window = new QWidget; QSpacerItem *spacer1 = new QSpacerItem(20, 10, QSizePolicy::Expanding, QSizePolicy::Expanding); QSpacerItem *spacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Expanding); QBoxLayout *layout = new QHBoxLayout; layout->addWidget(new QLineEdit("Foooooooooooooooooooooooooo")); layout->addSpacerItem(spacer1); layout->addWidget(new QLineEdit("Baaaaaaaaaaaaaaaaaaaaaaaaar")); layout->insertSpacerItem(0, spacer2); window->setLayout(layout); QVERIFY(layout->itemAt(0) == spacer2); QVERIFY(layout->itemAt(2) == spacer1); window->show(); }
void RatingWidget::init() { updateBounds(); m_total = qMin(m_max, static_cast<int>(m_widgets.count())); int i = 0; for( ; i < m_total; ++i) { m_widgets.at(i)->setPixmap(m_pixOff); } setUpdatesEnabled(false); QBoxLayout* l = ::qobject_cast<QBoxLayout*>(layout()); // move the clear button to right after the last star l->removeWidget(m_clearButton); l->insertWidget(i, m_clearButton); l->removeItem(m_clearSpacer); l->insertSpacerItem(i+1, m_clearSpacer); m_clearButton->hide(); setUpdatesEnabled(true); for( ; i < m_widgets.count(); ++i) { m_widgets.at(i)->setPixmap(QPixmap()); } update(); }
void QBoxLayoutProto::insertSpacerItem(int index, QSpacerItem *spacerItem) { QBoxLayout *item = qscriptvalue_cast<QBoxLayout*>(thisObject()); if (item) item->insertSpacerItem(index, spacerItem); }