コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: BGmot/Qt
//! [0]
MainWindow::MainWindow(QWidget *parent) :
        QWidget(parent),
        landscapeWidget(0),
        portraitWidget(0)
{
    landscapeWidget = new QWidget(this);
    landscape.setupUi(landscapeWidget);

    portraitWidget = new QWidget(this);
    portrait.setupUi(portraitWidget);
//! [0]

//! [1]
    connect(portrait.exitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(landscape.exitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(landscape.buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
            this, SLOT(onRadioButtonClicked(QAbstractButton*)));

    landscape.radioAButton->setChecked(true);
    onRadioButtonClicked(landscape.radioAButton);
//! [1]

//! [2]
#ifdef Q_WS_MAEMO_5
    setAttribute(Qt::WA_Maemo5AutoOrientation, true);
#endif
}
コード例 #2
0
DateChooserWidget::DateChooserWidget(QWidget *parent)
    : QWidget(parent), m_selectedRadioIndex(0) {
  QVBoxLayout *mainLayout = new QVBoxLayout;
  mainLayout->setMargin(0);
  mainLayout->setAlignment(Qt::AlignTop);

  // Time
  QHBoxLayout *timeLayout = new QHBoxLayout;

  m_timeRadioButton = new QRadioButton;
  m_timeRadioButton->setChecked(true);
  connect(m_timeRadioButton, SIGNAL(clicked()), this,
          SLOT(onRadioButtonClicked()));

  m_timeEdit = new QTimeEdit;
  m_timeEdit->setDisplayFormat("hh:mm");

  timeLayout->addWidget(m_timeRadioButton);
  timeLayout->addWidget(m_timeEdit);
  timeLayout->addWidget(new QLabel(tr("time ago.")));
  timeLayout->addStretch();
  mainLayout->addLayout(timeLayout);

  // Days
  QHBoxLayout *dayLayout = new QHBoxLayout;

  m_dayRadioButton = new QRadioButton;
  connect(m_dayRadioButton, SIGNAL(clicked()), this,
          SLOT(onRadioButtonClicked()));

  m_dayEdit = new QSpinBox;
  m_dayEdit->setRange(1, 99);
  m_dayEdit->setValue(1);
  m_dayEdit->setEnabled(false);

  dayLayout->addWidget(m_dayRadioButton);
  dayLayout->addWidget(m_dayEdit);
  dayLayout->addWidget(new QLabel(tr("days ago.")));
  dayLayout->addStretch();
  mainLayout->addLayout(dayLayout);

  // Weeks
  QHBoxLayout *weekLayout = new QHBoxLayout;

  m_weekRadioButton = new QRadioButton;
  connect(m_weekRadioButton, SIGNAL(clicked()), this,
          SLOT(onRadioButtonClicked()));

  m_weekEdit = new QSpinBox;
  m_weekEdit->setRange(1, 99);
  m_weekEdit->setValue(1);
  m_weekEdit->setEnabled(false);

  weekLayout->addWidget(m_weekRadioButton);
  weekLayout->addWidget(m_weekEdit);
  weekLayout->addWidget(new QLabel(tr("weeks ago.")));
  weekLayout->addStretch();
  mainLayout->addLayout(weekLayout);

  // Custom date
  QHBoxLayout *customDateLayout = new QHBoxLayout;

  m_dateRadioButton = new QRadioButton;
  connect(m_dateRadioButton, SIGNAL(clicked()), this,
          SLOT(onRadioButtonClicked()));

  m_dateTimeEdit = new QDateTimeEdit;
  m_dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm");
  QDate now = QDate::currentDate();
  m_dateTimeEdit->setMaximumDate(now);
  m_dateTimeEdit->setDate(now);
  m_dateTimeEdit->setEnabled(false);
  m_dateTimeEdit->setCalendarPopup(true);

  customDateLayout->addWidget(m_dateRadioButton);
  customDateLayout->addWidget(m_dateTimeEdit);
  customDateLayout->addWidget(new QLabel(tr("( Custom date )")));
  customDateLayout->addStretch();
  mainLayout->addLayout(customDateLayout);

  setLayout(mainLayout);
}