this->chuizhi1->addLayout(this->shuiping1); this->chuizhi1->addWidget(this->video_widget);
时间: 2023-06-21 11:04:22 浏览: 40
这行代码是使用Qt框架中的布局管理器将两个布局添加到一个垂直布局中,并将一个视频窗口小部件添加到该垂直布局中。具体来说,第一行代码将名为`shuiping1`的水平布局添加到名为`chuizhi1`的垂直布局中,第二行代码将名为`video_widget`的视频窗口小部件添加到`chuizhi1`中。这样做的目的是使这些控件自动适应窗口大小和布局变化。
相关问题
this->video_widget=new QVideoWidget(); //给它设置水平布局 this->allwindow = new QVBoxLayout();//设置垂直布局 this->showwindow = new QHBoxLayout();//设置水平布局 this->shuiping1=new QHBoxLayout(); this->chuizhi1=new QVBoxLayout(); //this->showwindow->addWidget(this->video_widget); this->timeslider = new QSlider(this); this->time1_lab = new QLabel("00:00",this); this->time2_lab=new QLabel("00:00",this); this->timeslider->setOrientation(Qt::Horizontal);//将进度条设置为水平方向 this->timeslider->setMaximumSize(700,5); this->shuiping1->addWidget(this->time1_lab); this->shuiping1->addWidget(this->timeslider); this->shuiping1->addWidget(this->time2_lab); this->chuizhi1->addWidget(this->shuiping1); this->chuizhi1->addWidget(this->video_widget); this->allwindow->addWidget(this->chuizhi1); this->allwindow->addWidget(this->ui->tab_3);提示error: no matching function for call to 'QVBoxLayout::addWidget(QHBoxLayout*&)' this->chuizhi1->addWidget(this->shuiping1); ^
根据错误信息,您正在尝试将 QHBoxLayout 对象作为参数传递给 QVBoxLayout 的 addWidget() 函数,但是该函数只接受 QWidget 类型的参数。您需要将 QHBoxLayout 中的组件(例如 QLabel 和 QSlider)添加到 QWidget 中,然后将该 QWidget 添加到 QVBoxLayout 中。
例如,您可以创建一个新的 QWidget 对象,将 QHBoxLayout 中的组件添加到该对象中,然后将该 QWidget 对象添加到 QVBoxLayout 中:
```cpp
QWidget *widget = new QWidget();
widget->setLayout(this->shuiping1);
this->chuizhi1->addWidget(widget);
```
或者,您可以将 QHBoxLayout 中的组件分别添加到 QVBoxLayout 中:
```cpp
this->chuizhi1->addLayout(this->shuiping1);
this->chuizhi1->addWidget(this->video_widget);
```
#include "mylogin.h" mylogin::mylogin(QWidget *parent) : QDialog(parent) { this->init_ui(); connect(this->bnt_login, &QPushButton::clicked, this, &mylogin::do_login); connect(this->bnt_register, &QPushButton::clicked , this ,&mylogin::do_enroll); } mylogin::~mylogin() { } void mylogin::init_ui() { this->setFixedSize(QSize(600,350)); this->setWindowTitle(tr("岑超升")); this->setWindowIcon(QIcon(":/src/1.png")); this->lb1 = new QLabel(); this->lb2 = new QLabel(); this->lb3 = new QLabel(); this->lb1->setFixedSize(QSize(560,200)); QPixmap pic; pic.load(":/src/2.png"); //this->lb1->setPixmap(pic.scaled(this->lb1->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); this->lb1->setPixmap(QPixmap(":/src/2.png")); this->lb2->setText(tr("用户名:")); this->lb3->setText(tr("密 码:")); this->usr_name_le = new QLineEdit(); //这两个参数后面传入信号中去,然后emit发射出去 this->usr_pass_le = new QLineEdit(); this->usr_pass_le->setEchoMode(QLineEdit::Password); this->bnt_login = new QPushButton(tr("登 陆")); this->bnt_register = new QPushButton(tr("注 册")); this->hb1 = new QHBoxLayout(); this->hb2 = new QHBoxLayout(); this->hb3 = new QHBoxLayout(); this->hb1->addWidget(this->lb2); this->hb1->addWidget(this->usr_name_le); this->hb2->addWidget(this->lb3); this->hb2->addWidget(this->usr_pass_le); this->hb3->addWidget(this->bnt_login); this->hb3->addWidget(this->bnt_register); this->vb1 = new QVBoxLayout(); this->vb1->addWidget(this->lb1); this->vb1->addLayout(this->hb1); this->vb1->addLayout(this->hb2); this->vb1->addLayout(this->hb3); this->setLayout(this->vb1); } void mylogin::do_login() { emit sig_login(usr_name_le->text(), usr_pass_le->text()); //需要把这里输入的账号密码信息发送到myapp那去,用到的函数是emit //需要自定义一个信号,sig_login //这个槽函数能够发出信号 } void mylogin::do_enroll() { emit sig_enroll(); }解释每一行代码
#include "mylogin.h" //引入自定义头文件mylogin.h
mylogin::mylogin(QWidget *parent) : QDialog(parent) { //mylogin的构造函数,继承自QDialog类,parent为其父窗口
this->init_ui(); //初始化UI界面
connect(this->bnt_login, &QPushButton::clicked, this, &mylogin::do_login); //连接登陆按钮的点击事件和槽函数do_login
connect(this->bnt_register, &QPushButton::clicked , this ,&mylogin::do_enroll); //连接注册按钮的点击事件和槽函数do_enroll
}
mylogin::~mylogin() { //mylogin的析构函数
}
void mylogin::init_ui() { //初始化UI界面的函数
this->setFixedSize(QSize(600,350)); //设置窗口大小
this->setWindowTitle(tr("岑超升")); //设置窗口标题
this->setWindowIcon(QIcon(":/src/1.png")); //设置窗口图标
this->lb1 = new QLabel(); //新建一个标签
this->lb2 = new QLabel(); //新建一个标签
this->lb3 = new QLabel(); //新建一个标签
this->lb1->setFixedSize(QSize(560,200)); //设置标签大小
QPixmap pic; //新建一个QPixmap类的对象pic
pic.load(":/src/2.png"); //将图片资源载入到pic中
this->lb1->setPixmap(QPixmap(":/src/2.png")); //设置标签的图片为载入的图片
this->lb2->setText(tr("用户名:")); //设置标签显示的文本
this->lb3->setText(tr("密 码:")); //设置标签显示的文本
this->usr_name_le = new QLineEdit(); //新建一个单行文本框
this->usr_pass_le = new QLineEdit(); //新建一个单行文本框
this->usr_pass_le->setEchoMode(QLineEdit::Password); //设置文本框的显示模式为密码模式
this->bnt_login = new QPushButton(tr("登 陆")); //新建一个按钮
this->bnt_register = new QPushButton(tr("注 册")); //新建一个按钮
this->hb1 = new QHBoxLayout(); //新建一个水平布局
this->hb2 = new QHBoxLayout(); //新建一个水平布局
this->hb3 = new QHBoxLayout(); //新建一个水平布局
this->hb1->addWidget(this->lb2); //将标签lb2添加到hb1布局中
this->hb1->addWidget(this->usr_name_le); //将单行文本框usr_name_le添加到hb1布局中
this->hb2->addWidget(this->lb3); //将标签lb3添加到hb2布局中
this->hb2->addWidget(this->usr_pass_le); //将单行文本框usr_pass_le添加到hb2布局中
this->hb3->addWidget(this->bnt_login); //将按钮bnt_login添加到hb3布局中
this->hb3->addWidget(this->bnt_register); //将按钮bnt_register添加到hb3布局中
this->vb1 = new QVBoxLayout(); //新建一个垂直布局
this->vb1->addWidget(this->lb1); //将标签lb1添加到vb1布局中
this->vb1->addLayout(this->hb1); //将hb1布局添加到vb1布局中
this->vb1->addLayout(this->hb2); //将hb2布局添加到vb1布局中
this->vb1->addLayout(this->hb3); //将hb3布局添加到vb1布局中
this->setLayout(this->vb1); //将vb1布局设置为mylogin的布局
}
void mylogin::do_login() { //登陆按钮的槽函数
emit sig_login(usr_name_le->text(), usr_pass_le->text()); //发射自定义信号sig_login,并将单行文本框usr_name_le和usr_pass_le中的内容作为参数传递
}
void mylogin::do_enroll() { //注册按钮的槽函数
emit sig_enroll(); //发射自定义信号sig_enroll
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)