qt中QtreeWidget与QstackWidget关联的问题
过程:要做一个图书管理系统,主界面是类似于这样的
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QStackedWidget>
#include<QTreeWidget>
#include<QTreeWidgetItem>
#include<QString>
#include<QLabel>
#include<QGridLayout>
#include<QHBoxLayout>
#include<QStringList>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QStackedWidget *stackWindow;
QHBoxLayout *mainLayout;
QTreeWidget *treeWidget;
QTreeWidgetItem *parentItem1;
QTreeWidgetItem *parentItem2;
QTreeWidgetItem *childItem1;
QTreeWidgetItem *childItem2;
QLabel *parentLable1;
QLabel *parentLable2;
QLabel *childLable1;
QLabel *childLable2;
public slots:
void change1(QTreeWidgetItem* item1,int count1);
};
#endif // WIDGET_H
#include "widget.h"
#include<QObject>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//connect(treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(change1(QTreeWidgetItem*,int)));
stackWindow =new QStackedWidget;
mainLayout =new QHBoxLayout;
treeWidget =new QTreeWidget(this);
parentItem1=new QTreeWidgetItem(treeWidget,QStringList("parent1"));
parentItem2=new QTreeWidgetItem(treeWidget,QStringList("parent2"));
childItem1=new QTreeWidgetItem(parentItem1,QStringList("child1"));
childItem2=new QTreeWidgetItem(parentItem2,QStringList("child2"));
parentLable1=new QLabel("parentWindow1");
parentLable2=new QLabel("parentWindow2");
childLable1=new QLabel("childLable1");
childLable2=new QLabel("childLable2");
stackWindow->addWidget(parentLable1);
stackWindow->addWidget(parentLable2);
stackWindow->addWidget(childLable1);
stackWindow->addWidget(childLable2);
mainLayout->addWidget(treeWidget);
mainLayout->addWidget(stackWindow);
// stackWindow->setCurrentIndex(2);
this->setLayout(mainLayout);
//QObject::connect(treeWidget,SIGNAL(itemPressed(QTreeWidgetItem*,int)),this,SLOT(change1(QTreeWidgetItem* ,int )));//注释1
QObject::connect(treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(change1(QTreeWidgetItem* ,int)));
}
Widget::~Widget()
{
}
void Widget::change1(QTreeWidgetItem *item1, int count1)
{
QTreeWidgetItem *item=item1;
if(item->text(count1)=="parent1")
{
stackWindow->setCurrentIndex(0);
}
else if(item->text(count1)=="parent2")
{
stackWindow->setCurrentIndex(1);
}
else if(item->text(count1)=="child1")
{
stackWindow->setCurrentIndex(2);
}
else if(item->text(count1)=="child2")
{
stackWindow->setCurrentIndex(3);
}
}
qt中QtreeWidget与QstackWidget关联的问题的更多相关文章
- Qt中的常用容器类(解释比较全面,有插图)
在Qt库中为我们提供了一系列的基于模板的容器类.这些类可以被用来存储特定类型的项.例如,如果你需要一个大小可以变得QString数组,那么可以使用QVector<QString>. 这些容 ...
- 第38课 Qt中的事件处理(上)
1. GUI程序原理回顾 (1)图形界面应用程序的消息处理模型 (2)思考:操作系统发送的消息如何转变为Qt信号 2. Qt中的事件处理 (1)Qt平台将系统产生的消息转换为Qt事件 ①Qt事件是一个 ...
- QT中的SOCKET编程(QT-2.3.2)
转自:http://mylovejsj.blog.163.com/blog/static/38673975200892010842865/ QT中的SOCKET编程 2008-10-07 23:13 ...
- Qt中,当QDockWidget的父窗口是一个不可以拖动的QTabWidget的时候实现拖动的方法
之前在做有关QDockWidget的内容时候遇到了瓶颈,那就是窗口弹出来之后拖动不了,也不可以放大和缩小,若是弹出来之后设置成了window的flags,也不可以拖动,而且也不是需要的效果. 1.弹出 ...
- Qt中事件处理的方法(三种处理方法,四种覆盖event函数,notify函数,event过滤,事件处理器。然后继续传递给父窗口。可观察QWidget::event的源码,它是虚拟保护函数,可改写)
一.Qt中事件处理的方式 1.事件处理模式一 首先是事件源产生事件,最后是事件处理器对这些事件进行处理.然而也许大家会问, Qt中有这么多类的事件,我们怎么样比较简便的处理每个事件呢?设想,如果是 ...
- QT中QMainWindow、QWidget、QDialog
QT中QMainWindow.QWidget.QDialog 简述 在分享所有基础知识之前,很有必要在这里介绍下常用的窗口-QWidget.QDialog.QMainWindow. 熟悉Qt的同学都应 ...
- Qt 中的事件处理(一)
1.图形界面应用程序的消息处理模型 特点: 基于操作系统才能运行 GUI应用程序提供的功能必须由用户触发 用户操作界面时操作系统是第一个感知的 系统内核的消息通过事件处理转变成QT的信号 2. Qt中 ...
- Qt中常用知识点
1:QRegExp 正则表达式 QRegExp regExp("[a-zA-Z][1-9][0-9]{0,2}"); xxx->setValidator(new QRegEx ...
- QT中自定义系统托盘的实现—c++语言为例
将要介绍的是:QT中自定义系统托盘(systemtray)的一个Demo,希望能帮需要的读者快速上手. 前提假设是诸位已经知道QT中的signals .slot以及资源文件,所以关于这些不会再累述. ...
随机推荐
- .net core中常用的属性
//IsNullOrWhiteSpace()判断字符串是否为空 指示指定的字符串是 null.空还是仅由空白字符组成,如果字符串的空白String a=" ";IsNullOrE ...
- eclipse中Tomcat服务器缓存位置,以及清理Tomcat缓存
在Eclipse中进行Web开发,一般都会将项目直接在Eclipse中的Tomcat服务器运行,有时候修改了程序和页面之后,运行结果还是原来的 tomcat服务器中缓存的程序或者页面,需要清理缓存之后 ...
- Editplus 竖选,竖插入技巧
竖选方法 1,Alt + C, 然后用鼠标拖选 2,按住Alt健,再用鼠标拖选 行首行尾批量添加字符 以及其它常用正则 操作:Ctrl + H, 调出查找窗口,勾选按正则表达式查询 行首批量添加 ...
- centos7 yum 安装mysql5.6
这里用科技大学的mysql yum源官方的源太慢 [root@localhost ~]# rpm -ivh http://mirrors.ustc.edu.cn/mysql-repo/mysql-co ...
- java串口通讯环境配置
用java实现串口通信(windows系统下),配置如下: 1.comm.jar放置到 JAVA_HOME/jre/lib/ext;2.win32com.dll放置到 JAVA_HOME/bin;3. ...
- 【Redis】主从同步
Redis提供了主从复制功能,主要是为了保证服务的高可用性.在redis.conf配置文件中通过设置,可以开启主从复制功能.或者在客户端中使用slaveof 命令开启该功能. slaveof < ...
- python class 2
//test.py 1 class Employee: 2 'all employee' 3 empCount = 0 4 def __init__(s ...
- end to end
深度学习中的end to end是什么意思? 端到端就是输入一个数据进入模型,然后模型直接可以输出你想要的结果,也就是一体性. 简单讲就是,Input--->系统(这里指神经网络)---> ...
- .NET 黑魔法 - 自定义日志扩展
我们开发程序时避免不了要有日志系统,我们希望有一个通用的.不夹杂任何方言的调用方式,简单地说就是保留微软日志框架的注入方式和使用方式. 比如我们希望这样调用: 我们不希望有个 IAbcLogger, ...
- idea上传项目到github出现"remote with selected name already exists"情况的解决
1. 2. 3.