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以及资源文件,所以关于这些不会再累述. ...
随机推荐
- 282A
#include <iostream> #include <string> using namespace std; int main() { int n, plus, sub ...
- [LeetCode] 110. Balanced Binary Tree_Easy tag: DFS
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- iOS 开发笔记-加载/初始化
ViewDidLoad 一般我们会在这里做界面上的初始化操作,比如往view中添加一些子视图.从数据库或者网络加载模型数据装配到子视图中 在自定义控制里 initWithFrame:一般用于添加控件, ...
- idc交叉引用
#查找所有调用MSHookFunction的地方 ea=LocByName("MSHookFunction") if None !=ea: refs = idautils.Code ...
- 30.get和post的区别
POST和GET的区别 Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个 ...
- BCB6.0 清除TPanel面板上的所有控件
方法一: panel->ComponentCount属性获得panel所拥有的控件个数 panel->Components[i]属性获得某一个控件 delete panel->Com ...
- Hibernate.编写xml文件无自动提示信息
Hibernate.编写xml文件无自动提示信息 注意: 配置 xxxx.hbm.xml 文件的自动提示.和配置 hibernate.cfg.xml 文件的提示,操作步骤是一样的.只是复制的文件内容. ...
- Bukkit编程之动态向yml文件中添加属性
yaml = new Yaml(); String goods = args[0]; String goodsNum = args[1]; YamlConfiguration yc = new Yam ...
- 事件响应模型(游戏引擎、JAVA中等应用)
事件,我们在生活中时时在产生事件并且做出响应,如早晨出门时,看见外面下雨了,这时候我们需要带把伞等情况! 在现实生活之中事件分为人为事件和自然事件,那么在计算机操作系统中也不例外,存在两种事件 1.人 ...
- django 网站的搭建(2)
这里使用nginx+uwsgi的方法来搭建生产环境 1,pip3.5 install uwsgi 下载uwsgi ,这里就不做测试了,一般不会出错 2,将django与uwsgi连接在一起 毕竟ru ...