コード例 #1
0
void tst_QFormLayout::setFormStyle()
{
    QWidget widget;
    QFormLayout layout;
    widget.setLayout(&layout);

#if 0 // QT_NO_STYLE_PLASTIQUE
    widget.setStyle(new QPlastiqueStyle());

    QVERIFY(layout.labelAlignment() == Qt::AlignRight);
    QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
    QVERIFY(layout.fieldGrowthPolicy() == QFormLayout::ExpandingFieldsGrow);
    QVERIFY(layout.rowWrapPolicy() == QFormLayout::DontWrapRows);
#endif

    widget.setStyle(QStyleFactory::create("windows"));

    QVERIFY(layout.labelAlignment() == Qt::AlignLeft);
    QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
    QVERIFY(layout.fieldGrowthPolicy() == QFormLayout::AllNonFixedFieldsGrow);
    QVERIFY(layout.rowWrapPolicy() == QFormLayout::DontWrapRows);

    /* can't directly create mac style or qtopia style, since
       this test is cross platform.. so create dummy styles that
       return all the right stylehints.
     */
    widget.setStyle(new DummyMacStyle());

    QVERIFY(layout.labelAlignment() == Qt::AlignRight);
    QVERIFY(layout.formAlignment() == (Qt::AlignHCenter | Qt::AlignTop));
    QVERIFY(layout.fieldGrowthPolicy() == QFormLayout::FieldsStayAtSizeHint);
    QVERIFY(layout.rowWrapPolicy() == QFormLayout::DontWrapRows);

    widget.setStyle(new DummyQtopiaStyle());

    QVERIFY(layout.labelAlignment() == Qt::AlignRight);
    QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
    QVERIFY(layout.fieldGrowthPolicy() == QFormLayout::AllNonFixedFieldsGrow);
    QVERIFY(layout.rowWrapPolicy() == QFormLayout::WrapLongRows);
}
コード例 #2
0
ファイル: status-window.cpp プロジェクト: vogel/kadu
void StatusWindow::createLayout()
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    QFormLayout *formLayout = new QFormLayout();
    mainLayout->addLayout(formLayout);
    formLayout->setMargin(0);
    formLayout->setVerticalSpacing(0);

    // status combo box

    StatusSelect = new QComboBox(this);
    formLayout->addRow(new QLabel(tr("Status") + ':'), StatusSelect);

    // spacing

    formLayout->addItem(new QSpacerItem(0, 4));

    // description combo box

    QHBoxLayout *descriptionSelectLayout = new QHBoxLayout();
    descriptionSelectLayout->setMargin(0);
    descriptionSelectLayout->setSpacing(0);

    DescriptionSelect = new QComboBox(this);
    DescriptionSelect->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    DescriptionSelect->setToolTip(tr("Select Previously Used Description"));
    descriptionSelectLayout->addWidget(DescriptionSelect);

    ClearDescriptionsHistoryButton = new QPushButton(m_iconsManager->iconByPath(KaduIcon("edit-clear")), "", this);
    ClearDescriptionsHistoryButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    ClearDescriptionsHistoryButton->setToolTip(tr("Clear Descriptions History"));
    descriptionSelectLayout->addWidget(ClearDescriptionsHistoryButton);

    formLayout->addRow(new QLabel(tr("Description") + ':'), descriptionSelectLayout);

    // description edit field

    QWidget *descriptionCounterLayoutWidget = new QWidget(this);
    QVBoxLayout *descriptionCounterLayout = new QVBoxLayout(descriptionCounterLayoutWidget);
    descriptionCounterLayout->setMargin(0);
    descriptionCounterLayout->setSpacing(5);

    descriptionCounterLayout->addStretch();

    DescriptionCounter = new QLabel(this);
    DescriptionCounter->setAlignment(formLayout->labelAlignment());
    descriptionCounterLayout->addWidget(DescriptionCounter);

    descriptionCounterLayout->addSpacing(2);   // 2 px bottom margin

    QWidget *descriptionEditLayoutWidget = new QWidget(this);
    QHBoxLayout *descriptionEditLayout = new QHBoxLayout(descriptionEditLayoutWidget);
    descriptionEditLayout->setMargin(0);
    descriptionEditLayout->setSpacing(0);

    DescriptionEdit = new KaduTextEdit(this);
    DescriptionEdit->installEventFilter(this);
    DescriptionEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    DescriptionEdit->setTabChangesFocus(true);
    descriptionEditLayout->addWidget(DescriptionEdit);

    QVBoxLayout *descriptionEraseLayout = new QVBoxLayout();
    descriptionEraseLayout->setMargin(0);
    descriptionEraseLayout->setSpacing(0);
    descriptionEraseLayout->addStretch();
    EraseButton = new QPushButton(m_iconsManager->iconByPath(KaduIcon("edit-clear-locationbar-rtl")), "", this);
    EraseButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    EraseButton->setToolTip(tr("Erase Description"));
    descriptionEraseLayout->addWidget(EraseButton);
    descriptionEditLayout->addLayout(descriptionEraseLayout);

    formLayout->addRow(descriptionCounterLayoutWidget, descriptionEditLayoutWidget);

    mainLayout->addSpacing(16);

    // dialog buttons

    QDialogButtonBox *buttonsBox = new QDialogButtonBox(Qt::Horizontal, this);

    SetStatusButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogOkButton), tr("&Set status"), this);
    SetStatusButton->setDefault(true);
    buttonsBox->addButton(SetStatusButton, QDialogButtonBox::AcceptRole);

    CancelButton = new QPushButton(tr("&Cancel"), this);
    CancelButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton));
    buttonsBox->addButton(CancelButton, QDialogButtonBox::RejectRole);

    mainLayout->addWidget(buttonsBox);
}