마스터욱
Toggle navigation
  • 회원가입 | 정보찾기
ICON NAVIGATION
정보수정 쪽지함 주변맛집 익명채팅
공지사항 채팅 개발문의 방명록
  • MAIN NAVIGATION
  • 메인
  • 마스터욱 공간
    • 마스터욱 소개
    • 개발 리스트
    • 공지사항
    • 방명록
  • 마스터욱 외부자료
    • 네이버
    • 티스토리
    • 깃허브(github)
  • 개인 프로젝트
    • 랜덤 이성 채팅
    • Auto 크롤링
    • Javascript 카카오 채팅
    • 파이썬 뉴스매매
    • C# 키움 주식 자동매매
    • C# 키움 주식 패턴 분석
    • PHP 욱보드
    • 업비트 자동매매 개발
    • 업비트 자동매매 일지
  • 개발 의뢰
    • 개발 문의
    • 개발 견적
    • 개발 피드백
    • FAQ
  • 개발 경험 Tip
    • PHP
    • JSP
    • HTML
    • Javascript
    • Android
    • C#
    • MySQL
    • Linux
    • Python
    • NodeJS
    • React
    • Vue.js
    • Flutter
    • 정규식
    • 기타
  • 커뮤니티
    • 자유게시판
    • 추천사이트
    • 영화
    • 여행
    • 유머
    • Overseas News
  • 맛집&즐길 거리 탐방
    • 맛집 정보
    • 즐길 거리 정보
    • 내 주위 맛집&즐길 거리
  • 공유 사진
    • 음식
    • 여행
    • 캐릭터
    • 배경
    • 기타
    • 이모티콘
    • 일러스트
  • 놀이터
    • 블록뽀시기
    • 트레이딩뷰
    • 로또 시뮬레이션
    • 쳇쳇 익명 채팅
    • 랜덤 이성 채팅
    • AI 채팅
    • 미니 채팅
    • 바이너리 테스트
    • 마번호 생성기
    • 바카라 시뮬레이션
    • 홀짝점수 테스트
    • 로또 분석기
SITE STATISTICS
  • - 명 현재 접속자
  • 1,874 명 오늘 방문자
  • 2,310 명 어제 방문자
  • 5,192 명 최대 방문자
  • 687,447 명 전체 방문자
  • 2,569 개 전체 게시물
  • 496 개 전체 댓글수
Facebook Twitter GooglePlus KakaoStory NaverBand
  1. 홈
  2. 파이썬
목록으로

QTableWidget 동적생성/삭제

마스터욱 4 212 0 0 2018-04-03 17:07:08

동적으로 테이블 row를 컨트롤하는걸 웹방식으로 생각했다가 단디 당한 기분이다. 

row 생성은 매우쉽다.

단순히 insertRow 만으로 가능하다.

하지만 중간에 row 를 삭제하는건 간단하지 않다.

만일 1,2,3의 row 가 있다고 가정할때 2번을 지우려고 한다면, 2번을 지우고, 3번을 2번 자리로 옮겨야 한다. 물론 4가 있다면 4도 3으로 옮겨야 한다.

결국 노가다 뛰어서 성공을 하긴 했다만, 이거말고 간단하게 해결하신 분이 있다면 좀 알려줭.

class OrderSetupDialog(QDialog, order_ui):
def __init__(self):
super().__init__()

# print("OrderSetupDialog 오픈됨." + str(order_ui))
try:
self.setupUi(self)
except Exception as error:
print(error)

self.btn_order_add.clicked.connect(self.order_table_add)
self.vars = locals()

def order_table_add(self):
cnt = self.order_table.rowCount()
self.btn_order_add_proc(cnt)

def btn_order_add_proc(self, rowCnt):
# print("btn_order_add_proc 호출됨")
# row = self.order_table.rowCount()
# row_index = self.order_row_index
# print("row = " + str(row) + ", row_index = " + str(row_index))

self.order_table.insertRow(rowCnt)

self.vars['edit_name_%d' % rowCnt] = QLineEdit()
self.order_table.setCellWidget(rowCnt, 0, self.vars['edit_name_%d' % rowCnt])

self.vars['edit_code_%d' % rowCnt] = QLineEdit()
self.order_table.setCellWidget(rowCnt, 1, self.vars['edit_code_%d' % rowCnt])

self.vars['btn_remove_%d' % rowCnt] = QPushButton("삭제" + str(rowCnt))
self.vars['btn_remove_%d' % rowCnt].clicked.connect(partial(self.btn_remove_clicked, rowCnt))
self.order_table.setCellWidget(rowCnt, 2, self.vars['btn_remove_%d' % rowCnt])

def btn_remove_clicked(self, index):
# print("btn_remove_clicked 호출, index = " + str(index))
# self.order_table.removeRow(index)
rowCnt = self.order_table.rowCount()
for i in range(rowCnt):
if index > i:
continue
elif index == i:
self.order_table.removeRow(index)
else:
edit_name_value = self.vars['edit_name_%d' % i].text()
edit_code_value = self.vars['edit_code_%d' % i].text()

upper_number = i - 1
self.btn_order_add_proc(upper_number)
self.vars['edit_name_%d' % upper_number].setText(edit_name_value)
self.vars['edit_code_%d' % upper_number].setText(edit_code_value)

self.order_table.removeRow(i)

ㅇㅇ

0
0

목록

Facebook Twitter GooglePlus KakaoStory NaverBand
4 Comments

비밀번호 확인

확인
댓글은 자신을 나타내는 '얼굴'입니다. *^^*
등록
자동등록방지 숫자를 순서대로 입력하세요.

댓글수정


글쓰기
검색
번호 제목 이름 날짜 조회
  • 25
    파이썬(Python) 을 활용한, 빗썸(bithumb) 공지사항 가져오기
    마스터욱
    조회수 561   24-11-24 17:18
    마스터욱
    24-11-24 17:18
    561
  • 24
    카카오톡 봇 만들기, 추천 링크
    마스터욱
    조회수 238   23-12-11 04:21
    마스터욱
    23-12-11 04:21
    238
  • 23
    [2] 파이썬 웹서버(webserver), 장고(django) 사용 [2]
    마스터욱
    조회수 358   23-11-05 19:32
    마스터욱
    23-11-05 19:32
    358
  • 22
    파이썬(Python)으로 exe 파일 만들기
    마스터욱
    조회수 284   23-10-24 13:31
    마스터욱
    23-10-24 13:31
    284
  • 21
    카카오톡 봇 만들기
    마스터욱
    조회수 182   23-10-10 17:12
    마스터욱
    23-10-10 17:12
    182
  • 20
    파이썬 간단한 웹뷰 구현
    마스터욱
    조회수 260   23-08-28 05:16
    마스터욱
    23-08-28 05:16
    260
  • 19
    [1] PyQt5 연결이 않되는 문제 [1]
    비회원
    조회수 147   21-09-02 23:25
    비회원
    21-09-02 23:25
    147
  • 18
    Timer(타이머) 사용시 주의사항!
    마스터욱
    조회수 165   18-05-03 00:10
    마스터욱
    18-05-03 00:10
    165
  • 17
    requests 의 성공유무 처리(status_code)
    마스터욱
    조회수 188   18-04-30 22:15
    마스터욱
    18-04-30 22:15
    188
  • 16
    json 익셉션 처리
    마스터욱
    조회수 159   18-04-24 15:28
    마스터욱
    18-04-24 15:28
    159
  • 15
    pyqt5 배포판 만들기 삽질여행기(파이큐티 .ui -> .py 변경작업)
    마스터욱
    조회수 149   18-04-10 15:48
    마스터욱
    18-04-10 15:48
    149
  • 14
    pyinstaller 로 배포판 만들기 옵션
    마스터욱
    조회수 160   18-04-10 13:46
    마스터욱
    18-04-10 13:46
    160
  • 13
    [4] QTableWidget 동적생성/삭제 [4]
    마스터욱
    조회수 213   18-04-03 17:07
    마스터욱
    18-04-03 17:07
    213
  • 12
    동적 변수 생성하기
    마스터욱
    조회수 169   18-04-03 00:18
    마스터욱
    18-04-03 00:18
    169
  • 11
    QT designer 가 실행이 되지 않을때
    마스터욱
    조회수 184   18-04-01 14:05
    마스터욱
    18-04-01 14:05
    184
  • 10
    pyinstaller 로 배포판 만들때, 발생하는 오류 해결방법
    마스터욱
    조회수 171   18-03-30 15:16
    마스터욱
    18-03-30 15:16
    171
  • 9
    pip 로 pyinstaller 설치
    마스터욱
    조회수 122   18-03-30 13:03
    마스터욱
    18-03-30 13:03
    122
  • 8
    from functools import partial 을 이용한 connect 에 파라메터 전달하기
    마스터욱
    조회수 151   18-03-22 00:12
    마스터욱
    18-03-22 00:12
    151
  • 7
    뉴스 자동매매 구현중 중간소스 점검
    마스터욱
    조회수 235   18-03-14 00:03
    마스터욱
    18-03-14 00:03
    235
  • 6
    파이참(PyCharm) 에서 pyqt5 설치방법
    마스터욱
    조회수 179   18-03-12 01:19
    마스터욱
    18-03-12 01:19
    179
글쓰기
검색
  • 1
  • 2
  • 다음

Search

개인정보처리방침
마스터욱. All rights reserved.

Close

0 명 접속중
Time Loading...