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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章