逛奔的蜗牛
我不聪明,但我会很努力
:: ::
新随笔
:: :: ::
管理
::
随笔分类
C/C++(67)
(rss)
Cocoa(26)
(rss)
Java(186)
(rss)
Mac(126)
(rss)
OpenGL(25)
(rss)
Qt(164)
(rss)
Qt自定义Widget(12)
(rss)
Xcode(5)
(rss)
其他编程(94)
(rss)
设计模式(2)
(rss)
外语(4)
(rss)
网文(74)
(rss)
搜索
最新评论
1. re: Java:用 Java 7 运行 IDEA 13
great post
--contact form
Qt: 创建List, 添加删除Item
#ifndef LISTWINDOW_H_
#define LISTWINDOW_H_
#include
<
QDialog
>
class
QPushButton;
class
QListWidget;
class
QWidget;
class
ListWindow :
public
QDialog
{
Q_OBJECT
public
:
ListWindow(QWidget
*
parent
=
0
);
virtual
~
ListWindow();
public
slots:
void
moveLeft();
void
moveRight();
private
:
QPushButton
*
moveLeftButton;
QPushButton
*
moveRightButton;
QListWidget
*
leftList;
QListWidget
*
rightList;
}
;
#endif
/**/
/*
LISTWINDOW_H_
*/
#include
"
ListWindow.h
"
#include
<
QPushButton
>
#include
<
QListWidget
>
#include
<
QWidget
>
#include
<
QHBoxLayout
>
#include
<
QVBoxLayout
>
#include
<
QGridLayout
>
#include
<
QStringList
>
#include
<
QListWidgetItem
>
ListWindow::ListWindow(QWidget
*
parent) :
QDialog(parent)
{
QGridLayout
*
gridLayout
=
new
QGridLayout();
gridLayout
->
addWidget(leftList
=
new
QListWidget(),
0
,
0
,
3
,
1
);
gridLayout
->
addWidget(moveLeftButton
=
new
QPushButton(
"
<<
"
),
0
,
1
,
1
,
1
);
gridLayout
->
addWidget(moveRightButton
=
new
QPushButton(
"
>>
"
),
1
,
1
,
1
,
1
);
gridLayout
->
addWidget(rightList
=
new
QListWidget(),
0
,
2
,
3
,
1
);
QObject::connect(moveLeftButton, SIGNAL(clicked()),
this
, SLOT(moveLeft()));
QObject::connect(moveRightButton, SIGNAL(clicked()),
this
, SLOT(moveRight()));
QStringList items;
items
<<
"
One
"
<<
"
Two
"
<<
"
Three
"
<<
"
Four
"
<<
"
Five
"
<<
"
Sechs
"
<<
"
Sieben
"
<<
"
One
"
<<
"
Two
"
<<
"
Three
"
<<
"
Four
"
<<
"
Five
"
<<
"
Sechs
"
<<
"
Sieben
"
;
leftList
->
addItems(items);
this
->
setLayout(gridLayout);
}
ListWindow::
~
ListWindow()
{
}
void
ListWindow::moveLeft()
{
//
if (rightList->currentItem() == 0) {
//
return;
//
}
//
//
QString text = rightList->currentItem()->text();
//
delete rightList->currentItem();
//
leftList->addItem(text);
//
The takeItem() method is used to remove an Item form one list without
//
having to delete it. TakeItem() no deleting or no creating, more efficient.
if
(rightList
->
selectedItems().count()
!=
1
)
{
return
;
}
QListWidgetItem
*
item
=
rightList
->
takeItem(rightList
->
currentRow());
leftList
->
addItem(item);
}
void
ListWindow::moveRight()
{
//
if (leftList->currentItem() == 0) {
//
return;
//
}
//
//
QString text = leftList->currentItem()->text();
//
delete leftList->currentItem();
//
rightList->addItem(text);
if
(leftList
->
selectedItems().count()
!=
1
)
{
return
;
}
QListWidgetItem
*
item
=
leftList
->
takeItem(leftList
->
currentRow());
rightList
->
addItem(item);
}
posted on 2008-03-22 01:24
逛奔的蜗牛
阅读(4015)
评论(0)
编辑
收藏
引用
所属分类:
Qt
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
相关文章:
Qt:编码范围
Qt:Windows Qt 去掉选中的虚线框
Qt:定制qDebug等输出的格式
Qt:给QWidget添加shadow效果
Qt:Q_DECLARE_METATYPE和qRegisterMetaType
Qt:绘制带高光的按钮
Qt:FontMetrics
Mac:Mac下安装PHP, MySql开发环境
Qt:无标题栏无边框程序的拖动和改变大小
Qt:Use Third Party Libraries
网站导航:
博客园
IT新闻
BlogJava
博问
Chat2DB
管理
Powered by:
C++博客
Copyright © 逛奔的蜗牛