0

Morning/Afternoon/Evening

I've hit a brick wall previously I was able to have a QLineEdit be able to give you autofill options such as:

Autofill (Can't embedded images so its a link)

Previously the values were sorted in a list and using QCompleter and QStringListModel this was possible.

Having moved my form that was all QLineEdits to now just a QTableWidget. I want to achieve the same effect as previous with QLineEdit where if you type in the field labaled "Fittings" it will preform as previous. The values that were before stored in a List are now in a SQL DB.

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtSql import *

import tkinter
import sqlite3
import sys

connection = sqlite3.connect("PriceList.db")

# Getting Screen info
root = tkinter.Tk()
root.withdraw()

def setup(uname):
    global user
    user = uname

# Layout
layout = QHBoxLayout()
right_side = QGridLayout()
right_side.setAlignment(Qt.AlignTop)
left_side = QVBoxLayout()



class QuotesWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(QuotesWindow, self).__init__(*args, **kwargs)

        # Window Settings
        self.setWindowTitle("Herpy - " + user)
        self.setWindowIcon(QIcon("icon.png"))
        self.showMaximized()

        # Right Side Enter Quote
        self.input_table()
        right_side.addWidget(self.tableWidget)

        # Mid Line
        mid_line = QFrame()
        mid_line.setFrameShape(QFrame.VLine)
        mid_line.setFrameShadow(QFrame.Sunken)

        # Left Side Details
        acc_bt = QPushButton("Account")
        left_side.addWidget(acc_bt)

        # Who
        who_box = QLineEdit()
        who_box.setPlaceholderText("Name")
        left_side.addWidget(who_box)
        # Street
        street_box = QLineEdit()
        street_box.setPlaceholderText("Street")
        left_side.addWidget(street_box)
        # Town
        town_box = QLineEdit()
        town_box.setPlaceholderText("Town")
        left_side.addWidget(town_box)
        # County
        county_box = QLineEdit()
        county_box.setPlaceholderText("County")
        left_side.addWidget(county_box)
        # Postcode
        postc_box = QLineEdit()
        postc_box.setPlaceholderText("Postcode")
        left_side.addWidget(postc_box)
        # Telephone
        telep_box = QLineEdit()
        telep_box.setPlaceholderText("Telephone Number")
        left_side.addWidget(telep_box)
        # Seperator
        left_line = QFrame()
        left_line.setFrameShape(QFrame.HLine)
        left_line.setFrameShadow(QFrame.Sunken)
        left_side.addWidget(left_line)

        # Author
        q_author = QLineEdit()
        q_author.setPlaceholderText(user)
        q_author.setReadOnly(True)
        left_side.addWidget(q_author)
        # Placed By
        placed_b = QLineEdit()
        placed_b.setPlaceholderText("Placed By")
        left_side.addWidget(placed_b)
        # Placed With
        placed_w = QLineEdit()
        placed_w.setPlaceholderText("Placed With")
        left_side.addWidget(placed_w)
        # Reference
        ref_input = QLineEdit()
        ref_input.setPlaceholderText("Reference")
        left_side.addWidget(ref_input)

        # To Fill Space
        left_side.addStretch(1)

        # Layouts
        layout.addLayout(left_side)
        layout.addWidget(mid_line)
        layout.addLayout(right_side)

        # Shortcut
        shortcut = QShortcut(QKeySequence("Shift+Return"), self)
        #shortcut.activated.connect(self.new_input)

    # Makes it fucking render
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
        self.show()

    def input_table(self):
        # Auto Fill for Fittings
        model = QSqlTableModel()
        model.select()
        completer = QCompleter()
        completer.setCompletionColumn(1)
        #completer.setCaseSensitivity(CaseInsensitive)
        #completer.setCompletionRole(QtCore.Qt.EditRole)


        #Create table
        headers = ["Fittings", "Quantity", "Price", "Total"]

        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(50)
        self.tableWidget.setColumnCount(4)
        self.tableWidget.setItem(0,0, QTableWidgetItem("Cell (1,1)"))
        self.tableWidget.move(0,0)

        self.tableWidget.setColumnWidth(1, 80)
        self.tableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)

        #self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

        #self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableWidget.setHorizontalHeaderLabels(headers)

Thanks in advance :) Sorry its a bit messy

Edit: Was marked a dupe and give sqlite3 table into QTableWidget, sqlite3, PyQt5 Can't see how it corresponds with my code, am I missing something?

Edit2: Changed text so its more understable

  • In your explanation does not indicate the problem you have, you put irrelevant things, so I assume that your problem is that you do not know how to fill the QTableWidget with data from a sqlite, I have modified the duplicate question to one where it indicates exactly how to do it. Please take the time and read [ask] and [answer] to improve your question. Tell me if the new duplicate question helps you. – eyllanesc Aug 02 '18 at 16:37
  • Edited, hope that makes it easier to understand. – BenjaminBarnes Aug 02 '18 at 17:02

0 Answers0