qt學習(一):代碼法佈局qt控件 比較基礎

  1. 三哥佈局管理器
QHBoxLayout在水平方向排列部件
QVBoxLayout在豎直方向上排列部件
QGridLayout在網格中排列部件
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(lable);
topLeftLayout->addWidget(lineEdit);

QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);

QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch(); //在close按鍵下方添加一個彈簧填空

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);

setWindowTitle("Find");
setFixedHeight(sizeHint().height());
在這段代碼佈局下的截圖


          2、在代碼中用到的函數
  • findButton->setDefault(true); //將find按鈕設置成對話框的默認按鈕通過enter鍵
  • findButton->setEnabled(false); //禁用了find按鍵
  • spinbox->setRange(0,130); //如下數字的取值範圍 如下

          3、在代碼中用到的控件
  • QLineEdit //長條狀的寫入框
  • QCheckBox //如上截圖的帶選定空的標籤
  • QPushButton
  • QSpinBox  //如下截圖中
  • QSlider //進度條
  • QObject::connect(slider,SIGNAL(valueChanged(int)),spinbox,SLOT(setValue(int))); //進度條或數字變化會發出valueChanged信號 通過數字也可設置進度條進度的slot函數 setValue(int)

         4、鎖定光標的快捷鍵方法  看截圖1
  • lable =new QLabel(tr("Find&what"));
    lineEdit = new QLineEdit;
    lable->setBuddy(lineEdit);
    //lable通過alt+w來確定焦點,,,又通過 setBuddy 將焦點傳遞給 lineEdit











發佈了27 篇原創文章 · 獲贊 9 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章