zoukankan      html  css  js  c++  java
  • QT的组件布局

    在QT的IDE下,编写一个自定义布局。

     1 #include<QApplication>
     2 #include<QWidget>
     3 #include<QSpinBox>
     4 #include<QSlider>
     5 #include<QHBoxLayout>
     6 
     7 int main (int argc,char *argv[])
     8 {
     9     QApplication app(argc, argv);
    10     QWidget * window = new QWidget;
    11     window->setWindowTitle("ENTER your age");
    12     QSpinBox *spinBox = new QSpinBox;
    13     QSlider *slider = new QSlider(Qt::Horizontal);
    14     spinBox->setRange(0,130);
    15     slider->setRange(0,130);
    16     QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
    17     QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    18     spinBox->setValue(35);
    19     QHBoxLayout*layout=new QHBoxLayout;
    20     layout->addWidget(spinBox);
    21     layout->addWidget(slider);
    22     window->setLayout(layout);
    23     window->show();
    24     return app.exec();
    25 }

    在qt creater 运行结果,如下

    用两个信号槽进行连接,QHBoxLayout是一个水平布局,按照从左向右的方向添加。

    这两个信号槽不会无限递归,因为回调回来的int值相同,就不会继续发生信号了。

    QT的三个布局,QHBoxLayout,水平布局,从左向右。

                             QVBoxLayout,垂直布局,从上到下。

                              QGridLayout,网状布局。

                         layout使用addWidget加载组件,使用addLayout添加子布局。

  • 相关阅读:
    各个数字类型取值范围以及推理
    进制转换原理
    位运算操作符_
    读取文件内容
    java中thread的start()和run()的区别
    二进制的负数转换
    位运算符号
    Hadoop的辉煌还能延续多久?
    Hadoop 新 MapReduce 框架 Yarn 详解
    MapReduce工作原理讲解
  • 原文地址:https://www.cnblogs.com/132818Creator/p/7207692.html
Copyright © 2011-2022 走看看