Python Forum
Displaying database info in QTableWidget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying database info in QTableWidget
#6
They are not windows. They are classes that put stuff in a window. I see this done in tkinter a lot, probably because tkinter does strange things like initialize tkinter and create a window at the same time (Tk()). In Qt I am more used to seeing a window class which is a subclass of a Qt class. Such as class MyMainWindow(qtwidgets.QMainWindow).

If Ui_MainWindow was a window you would not be doing this:
class Ui_MainWindow(object):
    def SetupUi(self, MainWindow):
        super().__init__()
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowTitle("Phreesia Hardware")
        MainWindow.setWindowModality(QtCore.Qt.NonModal)
        MainWindow.resize(900, 350)
...
    window = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()2
    ui.SutupUi(window)
Instead your program would look more like this:
class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setWindowModality(QtCore.Qt.NonModal)
        self.resize(900, 350)
...
    ui = Ui_MainWindow()
    ui.setObjectName("MainWindow")
    ui.setWindowTitle("Phreesia Hardware")
Differences are subtle, but making the UI_MainWindow class a window means it understands all the commands you can send to a window. I moved setObjectName and setWindowTitle out of the Ui_MainWindow class because now I can make two of these windows if I want and assign them different titles and give them different names.
thewolf likes this post
Reply


Messages In This Thread
RE: Displaying database info in QTableWidget - by deanhystad - Apr-03-2021, 01:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt5 form not displaying my data from SQLite3 Database Linuxdesire 2 5,058 Jan-10-2023, 09:51 PM
Last Post: gradlon93
  [PyQt] [Solved]Help displaying SQLite Database Extra 9 2,900 May-21-2022, 08:03 PM
Last Post: Extra
  [PyQt] QTableWidget print problem JokerSob 8 4,922 Jan-28-2022, 06:08 PM
Last Post: Axel_Erfurt
  [PyQt] How do I display the DB table I will choose from the QComboBox in QTableWidget JokerSob 2 2,373 Aug-05-2021, 03:00 PM
Last Post: JokerSob
  [PyQt] Help: check content of combobox in horizontal header of QTableWidget mart79 1 3,444 Jul-26-2020, 06:18 PM
Last Post: deanhystad
  [PyQt] Add validation (regex) to QTableWidget cells mart79 0 2,802 May-05-2020, 12:51 PM
Last Post: mart79
  [Tkinter] Displaying Data from a database and run a function when clicked? PythonNPC 1 2,111 Mar-11-2020, 08:16 PM
Last Post: Larz60+
  [PyQt] QTableWidget stylesheet error mart79 3 6,547 Feb-26-2020, 04:54 PM
Last Post: Denni
  [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget YoshikageKira 6 7,182 Jan-02-2020, 04:32 PM
Last Post: Denni
  [PyQt] QTableWidget cell validation littleGreenDude 1 7,747 Jan-18-2019, 07:44 PM
Last Post: littleGreenDude

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020