Qt QStackedWidget分页中遇到BUG,寻求帮助,急急急急,回答得好有追加
代码如下QWidget(parent){widget=newQWidget;//左侧布局QVBoxLayout*buttonLayout=newQVBoxLayout;Q...
代码如下
QWidget(parent)
{
widget = new QWidget;
//左侧布局
QVBoxLayout *buttonLayout = new QVBoxLayout;
QWidget *leftWidget = new QWidget(this); //新建一个QWidget
buttonLayout->addWidget(leftWidget);
QPushButton *button1 = new QPushButton(leftWidget);
QPushButton *button2 = new QPushButton(leftWidget);
QPushButton *button3 = new QPushButton(leftWidget);
QPushButton *button4 = new QPushButton(leftWidget);
//右边布局
QGridLayout *rightLayout = new QGridLayout;
stackedWidget = new QStackedWidget;
rightLayout->addWidget(stackedWidget);
stackedWidget->addWidget(creat_1Page);
stackedWidget->addWidget(creat_2Page);
stackedWidget->addWidget(creat_3Page);
stackedWidget->addWidget(creat_4Page);
connect(button1, SIGNAL(clicked()),stackedWidget, SLOT(slot_1()));
connect(button2, SIGNAL(clicked()),stackedWidget, SLOT(slot_2()));
connect(button3, SIGNAL(clicked()),stackedWidget, SLOT(slot_3()));
connect(button4, SIGNAL(clicked()),stackedWidget, SLOT(slot_4()));
//双表关联
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(buttonLayout);
mainLayout->addLayout(rightLayout);
mainLayout->addWidget(stackedWidget);
setLayout(mainLayout);
stackedWidget->showNormal();
}
Widget::~Widget()
{
}
void Widget::slot_1()
{
stackedWidget->setCurrentIndex(0);
}
void Widget::slot_2()
{
stackedWidget->setCurrentIndex(1);
}
void Widget::slot_3()
{
stackedWidget->setCurrentIndex(2);
}
void Widget::slot_4()
{
stackedWidget->setCurrentIndex(3);
}
void Widget::creatWidget_1()
{
creat_1Page = new QWidget;
}
void Widget::creatWidget_2()
{
creat_2Page = new QWidget;
}
void Widget::creatWidget_3()
{
creat_3Page = new QWidget;
}
void Widget::creatWidget_4()
{
creat_4Page = new QWidget;
}
或者谁能告诉我怎样在linux下用qt代码实现点击按钮分页。就是左边是一竖排按钮,右边实现Qwiget的分页。回答准确的有追加 展开
QWidget(parent)
{
widget = new QWidget;
//左侧布局
QVBoxLayout *buttonLayout = new QVBoxLayout;
QWidget *leftWidget = new QWidget(this); //新建一个QWidget
buttonLayout->addWidget(leftWidget);
QPushButton *button1 = new QPushButton(leftWidget);
QPushButton *button2 = new QPushButton(leftWidget);
QPushButton *button3 = new QPushButton(leftWidget);
QPushButton *button4 = new QPushButton(leftWidget);
//右边布局
QGridLayout *rightLayout = new QGridLayout;
stackedWidget = new QStackedWidget;
rightLayout->addWidget(stackedWidget);
stackedWidget->addWidget(creat_1Page);
stackedWidget->addWidget(creat_2Page);
stackedWidget->addWidget(creat_3Page);
stackedWidget->addWidget(creat_4Page);
connect(button1, SIGNAL(clicked()),stackedWidget, SLOT(slot_1()));
connect(button2, SIGNAL(clicked()),stackedWidget, SLOT(slot_2()));
connect(button3, SIGNAL(clicked()),stackedWidget, SLOT(slot_3()));
connect(button4, SIGNAL(clicked()),stackedWidget, SLOT(slot_4()));
//双表关联
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(buttonLayout);
mainLayout->addLayout(rightLayout);
mainLayout->addWidget(stackedWidget);
setLayout(mainLayout);
stackedWidget->showNormal();
}
Widget::~Widget()
{
}
void Widget::slot_1()
{
stackedWidget->setCurrentIndex(0);
}
void Widget::slot_2()
{
stackedWidget->setCurrentIndex(1);
}
void Widget::slot_3()
{
stackedWidget->setCurrentIndex(2);
}
void Widget::slot_4()
{
stackedWidget->setCurrentIndex(3);
}
void Widget::creatWidget_1()
{
creat_1Page = new QWidget;
}
void Widget::creatWidget_2()
{
creat_2Page = new QWidget;
}
void Widget::creatWidget_3()
{
creat_3Page = new QWidget;
}
void Widget::creatWidget_4()
{
creat_4Page = new QWidget;
}
或者谁能告诉我怎样在linux下用qt代码实现点击按钮分页。就是左边是一竖排按钮,右边实现Qwiget的分页。回答准确的有追加 展开
3个回答
展开全部
用QListWidget和QStackWidget控件完成,QListWiget可以设置每一项的内容,通过信号SIGNAL(currentRowChanged(int))把它和QStackWidget的槽SLOT(setCurrentIndex(int))联系起来。
给出部分代码: ////////////////////////左侧菜单(8)
list = new QListWidget();
list->setAcceptDrops(false);
list->setSpacing(10);
str = QString::fromLocal8Bit("通用设置");
list->addItem(new QListWidgetItem(QIcon(":/images/common.png"),str));
str = QString::fromLocal8Bit("测温设置");
list->addItem(new QListWidgetItem(QIcon(":/images/temperset.png"),str));
str = QString::fromLocal8Bit("网络设置");
list->addItem(new QListWidgetItem(QIcon(":/images/common.png"),str));
str = QString::fromLocal8Bit("SD卡管理");
list->addItem(new QListWidgetItem(QIcon(":/images/sdcard.png"),str));
str = QString::fromLocal8Bit("录像抓图");
list->addItem(new QListWidgetItem(QIcon(":/images/videosnap.png"),str));
str = QString::fromLocal8Bit("文件管理");
list->addItem(new QListWidgetItem(QIcon(":/images/filemanage.png"),str));
str = QString::fromLocal8Bit("测温模式");
list->addItem(new QListWidgetItem(QIcon(":/images/testmode.png"),str));
str = QString::fromLocal8Bit("系统维护握册");
list->addItem(new QListWidgetItem(QIcon(":/images/maintain.png"),str));
list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
list->setFrameShape(QFrame::NoFrame);
list->setViewMode(QListWidget::IconMode);
///////////////////////////右侧堆段肆宏窗口雹笑
main_stack = new QStackedWidget();
main_stack->setFrameShape(QFrame::Box);
main_stack->setStyleSheet("QStackedWidget {background-image: url(:/images/title.png);}");
//[1]通用设置
common = new common_menu(main_stack);
//[2]测温设置
temper_set = new temperature(main_stack);
//[3]网络设置
net_set = new internet(main_stack);
//[4]SD卡管理
sd_manager = new sd_card(main_stack);
//[5]录像抓图
video_snap = new video_manager(main_stack);
//[6]文件管理
file_manager = new manager_file(main_stack);
//[7]测温模式
test_mode = new temper_mode(main_stack);
//[8]系统维护
maintain = new sys_maintain(main_stack);
/////////////////////////////////布局
layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->addWidget(list);
layout->addWidget(main_stack);
layout->setStretch(0,1);
layout->setStretch(1,4);
layout->addStretch();
connect(list,SIGNAL(currentRowChanged(int)),main_stack,SLOT(setCurrentIndex(int)));
给出部分代码: ////////////////////////左侧菜单(8)
list = new QListWidget();
list->setAcceptDrops(false);
list->setSpacing(10);
str = QString::fromLocal8Bit("通用设置");
list->addItem(new QListWidgetItem(QIcon(":/images/common.png"),str));
str = QString::fromLocal8Bit("测温设置");
list->addItem(new QListWidgetItem(QIcon(":/images/temperset.png"),str));
str = QString::fromLocal8Bit("网络设置");
list->addItem(new QListWidgetItem(QIcon(":/images/common.png"),str));
str = QString::fromLocal8Bit("SD卡管理");
list->addItem(new QListWidgetItem(QIcon(":/images/sdcard.png"),str));
str = QString::fromLocal8Bit("录像抓图");
list->addItem(new QListWidgetItem(QIcon(":/images/videosnap.png"),str));
str = QString::fromLocal8Bit("文件管理");
list->addItem(new QListWidgetItem(QIcon(":/images/filemanage.png"),str));
str = QString::fromLocal8Bit("测温模式");
list->addItem(new QListWidgetItem(QIcon(":/images/testmode.png"),str));
str = QString::fromLocal8Bit("系统维护握册");
list->addItem(new QListWidgetItem(QIcon(":/images/maintain.png"),str));
list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
list->setFrameShape(QFrame::NoFrame);
list->setViewMode(QListWidget::IconMode);
///////////////////////////右侧堆段肆宏窗口雹笑
main_stack = new QStackedWidget();
main_stack->setFrameShape(QFrame::Box);
main_stack->setStyleSheet("QStackedWidget {background-image: url(:/images/title.png);}");
//[1]通用设置
common = new common_menu(main_stack);
//[2]测温设置
temper_set = new temperature(main_stack);
//[3]网络设置
net_set = new internet(main_stack);
//[4]SD卡管理
sd_manager = new sd_card(main_stack);
//[5]录像抓图
video_snap = new video_manager(main_stack);
//[6]文件管理
file_manager = new manager_file(main_stack);
//[7]测温模式
test_mode = new temper_mode(main_stack);
//[8]系统维护
maintain = new sys_maintain(main_stack);
/////////////////////////////////布局
layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->addWidget(list);
layout->addWidget(main_stack);
layout->setStretch(0,1);
layout->setStretch(1,4);
layout->addStretch();
connect(list,SIGNAL(currentRowChanged(int)),main_stack,SLOT(setCurrentIndex(int)));
更多追问追答
追问
这个例子太常见了,我想做的是左边是一竖排按钮,右边分页。左边不用QListWiget
追答
使用qlistwidget比较合理,方便在各个窗口切换,并且可以滑动左侧面板!如果一定要用按钮的话,请把源码给我!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
吓坏我了,你的SDK装好了吗?Helloqt程序能编译吗?
更多追问追答
追问
还有,我是在linux平台下装得QT4
追答
看你样子Linux和Qt毛都不会。
你去nokia下个完整的QtSDK装上,用SDK里的QtCreator写程序,
环境变量和其他的东西SDK会自己配好。
QtSDK:
http://qt.nokia.com/downloads/sdk-linux-x11-32bit-cpp-offline
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你要说清楚你的BUG是什么啊
更多追问追答
追问
就是出现那个错误报告工具,有只小虫那个
追答
不太清楚啦,你看那个编译那里有什么错误,贴上来吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询