Qt4:コントロールを使う


Qt4:百の定石


ここでいうコントロールとはラジオボタン等のWidgetのことです。

  • QSpinBox?:: 数値を入れるコントロールです。
    QSpinBox *zoomSpinBox = new QSpinBox;
    zoomSpinBox->setRange(0, 1000);
    zoomSpinBox->setSingleStep(10);
    zoomSpinBox->setSuffix("%");
    zoomSpinBox->setSpecialValueText(tr("Automatic"));
    zoomSpinBox->setValue(100);
    connect(zoomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(hoge()) ) ;
  • QSlider:: 数値を入れるコントロールです。
    QSlider *mySlider = new QSlider(Horizontal, this);
    mySlider->setObjectName(tr("Hoge")); 
    mySlider->setMinimum(minValue);
    mySlider->setMaximum(maxValue);
    mySlider->setPageStep(pageStep);
    mySlider->setValue(value);
    connect( slider, SIGNAL(valueChanged(int)), lcd, SLOT(hoge(int)) ) ;
  • QPushButton?:: ボタンです。
    QPushButton* cat = new QPushButton("にゃんこ", this) ;
    QPixmap pixmap(20, 10) ;
    QPainter qp(&pixmap) ;
    QBrush qb(QColor(red, green, blue)) ;
    qp.fillRect(0, 0, 20, 10, qb) ;
    cat->setIcon(QIcon(pixmap)) ;
    connect( cat, SIGNAL(clicked()), this, SLOT(miya()) );
  • QLineEdit?:: テキストを入力します。
    QLineEdit* edit = new QLineEdit(this) ;
    edit->setGeometry(10, 40, 180, 30) ;
    edit->setText("Hello") ;
    connect(edit, SIGNAL(returnPressed()), this, SLOT(accept()) ) ;
  • QComboBox?:: メニュー選択形式のコントロールです。
    QComboBox *team = new QComboBox(this ,"read-only combobox" );
    team->addItems(MenuList) ;
    team->setCurrentIndex(1) ;
    int index = team->currentIndex() ;
    connect( team, SIGNAL(activated(int)), this, SLOT(hoge(int)) );
  • QRadioButton?:: ラジオボタンのクラスです。ラジオボタンはただ1個だけ選択されていなければなりません。下の絵のようにボタンが並ぶ場合はQt4:Widget のボックスを作る。を参照してください。
    b = new QRadioButton( "watch TV" , this );
    connect(b, SIGNAL(clicked()), this, SLOT(hogehoge()) ) ;
  • QCheckBox?:: チェックマークをセットします。ラジオボタンと違って複数チェックが入ってもかまいません。
    QCheckbox* cb = new QCheckBox("music", this ) ;
    cb->setChecked(true) ;
    connect( cb, SIGNAL(clicked()), this, SLOT(hogehoge()) ) ;
                             :
    if (cb->isChecked()) .....

最新の20件

2020-12-25 2007-03-14 2006-10-30 2006-11-09 2007-03-14 2006-11-09 2006-11-10 2006-11-09 2008-05-20 2007-11-07 2007-11-01

今日の20件

  • counter: 487
  • today: 1
  • yesterday: 0
  • online: 1