滚动条控制Qt中滚动区域的滚动
我是 QT 框架的新手,所以请耐心等待...
我被赋予了这个简单的任务,我有一系列 Qlabel,每个 Qlabel 都设置为 .png 图片,
这些多个 Qlabel 不适合屏幕,所以这里的滚动条会很方便......
所以我将所有项目插入滚动区域,
看看情况:
我想要滚动条控制滚动区域上下滚动
我已经创建了插槽 slipMoved( )当幻灯片移动时吸收滚动条生成的信号,
这是 Form.cpp 类:
//Form.cpp
#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
#include<QScrollArea>
#include<QScrollBar>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
void Form::slideMoved()
{
}
我的问题如下,
-我这样做对吗?或者他们是其他更简单的方法吗?
-slideMoved() 应该如何通过上下滚动滚动区域来处理事件
请具体说明,因为我是新手,我将不胜感激
谢谢
I am new to QT framework , so please bear with me...
I have been given this simple task , i have a series of Qlabels each one is set to a .png pic
these Multiple Qlabels don't fit the screen , so a scroll bar here would be handy ...
so i inserted all of my items in my Scroll area
take a look at the situation :
i want the scroll bar to controll the Scroll area to scroll up and down
I Have created the slot slideMoved() that absorbs the signal generated by the scroll bar when the the slide is moved
this is the Form.cpp class :
//Form.cpp
#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
#include<QScrollArea>
#include<QScrollBar>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
void Form::slideMoved()
{
}
My Questions are the following,
-am i doing this right , or their is an other simpler way to do that ?
-how should slideMoved() handle the event by scrolling up and down the scroll area
Please be Specific since i am new to this, I would appreciate that
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要创建插槽,则必须指定它是插槽。
这样做是这样的
然后你必须按照你的方式实现这个插槽。
最后,您必须将信号连接到您的插槽,以便在发出信号时触发您的插槽。
然后您可以创建一个新变量来保存之前的滑块值。
每次执行插槽时,您都会将前一个值与新值进行比较,以了解运动情况。
插槽可以是这样的。
您可以在此处阅读有关信号和槽的更多信息
If you want to create a slot you must specify that it is a slot.
This is done like this
Then you have to implement this slot in the way you did.
In the end you have to connect a signal to your slot in order to trigger your slot when the signal is being emmited.
Then you can create a new variable to hold the previous slider value.
Every time your slot will be executed you will compare the previous value with the new one in order to understand the movement.
The slot can be something like this.
You can read more about signals and slots here