Benutzer-Werkzeuge

Webseiten-Werkzeuge


en:qt

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
en:qt [2022/08/23 19:22] – [TableView] roehneren:qt [2024/05/07 17:09] (aktuell) roehner
Zeile 1: Zeile 1:
 ===== Precondition ===== ===== Precondition =====
-To use the modern and powerful Qt library, you need to install the PyQt6 package. To do this, call up the command Install //tools/install packages with PIP// via the GuiPy tools menu and enter //PyQt6// as the package name.+To use the modern and powerful Qt library, you need to install the PyQt6 package. To do this, call up the command //tools/install packages with PIP// via the GuiPy tools menu and enter //PyQt6// as the package name. You can open a console via //Tools/Command Prompt// and then use //pip list// to display the list of currently installed packages.
  
-Alternatively, you can install the PySide6 package and replace PyQt6 with PySide6 in the Qt template. The Qt template can be found in the configuration under Editor/File templates.+In addition, you should install the //PySide6// package in order to be able to run source code based on it. 
 + 
 +One of the major changes in PyQt6 is the need to use fully qualified names for enums and flags. For example in PyQt5 and PySide2 you could just write Qt.DecorationRole or Qt.AlignLeft. This shortened form no longer works in PyQt6, you now have to write Qt.ItemDataRole.DisplayRole or Qt.Alignment.AlignLeft. This change affects all enums and flag types in Qt. Both long and short names are still supported in PySide6. 
 + 
 +If you prefer to work with the shortened forms, you can replace PyQt6 with PySide6 in the Qt template. The Qt template can be found in the configuration under Editor/File templates.
  
 Detailed information about Qt can be found in the [[https://doc.qt.io/qtforpython/PySide6/QtWidgets/index.html#module-PySide6.QtWidgets|documentation]] or [[https://doc.qt.io/qt-6/index.html|documentation Qt]]. Detailed information about Qt can be found in the [[https://doc.qt.io/qtforpython/PySide6/QtWidgets/index.html#module-PySide6.QtWidgets|documentation]] or [[https://doc.qt.io/qt-6/index.html|documentation Qt]].
Zeile 14: Zeile 18:
 The Python code of a GUI program is saved with the .pyw file extension, the associated form with the .pfm file extension. Both will open together. If you close the form, you can open it again using the {{:arrange.png}} icon in the editor toolbar. The Python code of a GUI program is saved with the .pyw file extension, the associated form with the .pfm file extension. Both will open together. If you close the form, you can open it again using the {{:arrange.png}} icon in the editor toolbar.
  
 +===== Qt Base =====
 ==== Label ==== ==== Label ====
 {{:label.png}} {{:label.png}}
Zeile 63: Zeile 68:
         pass         pass
 </code> </code>
-In order to keep track of the source text even when there are many buttons in a form, the buttons and associated event methods are automatically named according to the label in the Text attribute of the object inspector.+In order to keep track of the source text even when there are many buttons in a form, the buttons and associated event methods are automatically named according to the label in the //Text// attribute of the object inspector
 + 
 +Double-clicking on a button in the design window positions the cursor on the associated event method.
 ---- ----
 ==== CheckBox ==== ==== CheckBox ====
 {{:checkbutton.png}} {{:checkbutton.png}}
-A CheckBox may or may not be selected. The boolean method //isChecked()// returns the current status.+A CheckBox may or may not be selected. The boolean method //isChecked()// returns the current status, with //setChecked(bool)// a value is set.
  
 Example:  Example: 
Zeile 134: Zeile 141:
  
 A ScrollBar can be used to scroll, in which the visible section of a displayed text or graphic is moved. Some widgets such as B. PlainTextEdit, ListBox or TableWidget are automatically provided with scrollbars. A ScrollBar can be used to scroll, in which the visible section of a displayed text or graphic is moved. Some widgets such as B. PlainTextEdit, ListBox or TableWidget are automatically provided with scrollbars.
 +----
 +==== Canvas ====
 +{{:canvas.png}}
 +A Canvas is a drawing surface. The Painter for the canvas has many drawing possibilities.
 +
 +Example:
 +<code python>
 +  def pushButton1_clicked(self, checked):
 +      self.canvas1Painter.drawEllipse(0, 0, 100, 100)  # draw a circle
 +      self.canvas1Painter.drawLine(0, 100, 100, 0)     # draw a line
 +      self.canvas1.setPixmap(self.canvas1Pixmap)       # show the drawing
 +</code>
 +
 +A Canvas consists of a Label widget that hosts the canvas. Then we have a pixmap the size of the Label, which is the actual drawing surface. And third, we have the QPainter that draws on the pixmap.
 +
 +A shown in the example, you can easily draw on the canvas with the painter. When the drawing is finished, you have to show it with 
 +<code python>self.canvas1.setPixmap(self.canvas1Pixmap)</code>
 ---- ----
 ==== Frame ==== ==== Frame ====
Zeile 139: Zeile 163:
 A Frame wigdet is a container for other widgets. Frames are a good way to structure graphic interfaces. To place a widget in a frame, click it in the toolbar and then click in the frame, or drag and drop a widget from the toolbar over the frame. If you move a frame, the widgets it contains are also moved. A Frame wigdet is a container for other widgets. Frames are a good way to structure graphic interfaces. To place a widget in a frame, click it in the toolbar and then click in the frame, or drag and drop a widget from the toolbar over the frame. If you move a frame, the widgets it contains are also moved.
 ---- ----
-==== LabelFrame ====+==== GroupBox ====
 {{:labelframe.png}} {{:labelframe.png}}
 Like a Frame widget, a GroupBox is a container for other widgets. A GroupBox also has a frame with an integrated label. Like a Frame widget, a GroupBox is a container for other widgets. A GroupBox also has a frame with an integrated label.
  
-GuiPy graphically displays a ButtonGroup for RadioButtons using a GroupBox.+GuiPy graphically displays a ButtonGroup for RadioButtons or CheckBoxes using a GroupBox.
 ---- ----
 ==== Slider==== ==== Slider====
Zeile 187: Zeile 211:
 A Menu widget is a context menu that is invoked with the right mouse button. As with the MenuBar widget, it is defined using the //MenuItems// attribute. A Menu widget is a context menu that is invoked with the right mouse button. As with the MenuBar widget, it is defined using the //MenuItems// attribute.
  
-You can assign a context menu to each widget. To do this, you specify the name of the context menu in the //ContextMenu// attribute of the widget.+You can assign a context menu to each widget. To do this, you specify the name of the menu in the //ContextMenu// attribute of the widget.
 ---- ----
 ==== TabWidget ==== ==== TabWidget ====
Zeile 222: Zeile 246:
 {{:sizegrip.png}} A StatusBar widget represents a status bar at the bottom of the application window. A handle for resizing the application window is indicated by dots in the lower right corner. {{:sizegrip.png}} A StatusBar widget represents a status bar at the bottom of the application window. A handle for resizing the application window is indicated by dots in the lower right corner.
 ---- ----
 +===== Qt Controls =====
 ==== TextEdit ==== ==== TextEdit ====
 {{:textedit.png}} A TextEdit widget displays a multi-line text like the PlainTextEdit widget, but in HTML or Markdown format. The HTML text to be displayed can be entered in the object inspector via the //Html// attribute. In a program, the text can be read with //toHTML()// and written with //setHTML()// at runtime. Other methods are described in the  [[https://doc.qt.io/qtforpython/PySide6/QtWidgets/QTextEdit.html|documentation]]. {{:textedit.png}} A TextEdit widget displays a multi-line text like the PlainTextEdit widget, but in HTML or Markdown format. The HTML text to be displayed can be entered in the object inspector via the //Html// attribute. In a program, the text can be read with //toHTML()// and written with //setHTML()// at runtime. Other methods are described in the  [[https://doc.qt.io/qtforpython/PySide6/QtWidgets/QTextEdit.html|documentation]].
en/qt.1661275376.txt.gz · Zuletzt geändert: 2022/08/23 19:22 von roehner