GUI dynamisch ändern
-
hi,
ich versuche gerade mit qtcreator ein Programm zu schreiben. Nun will ich das gui dynamisch ändern.
ui-code:<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1376</width> <height>1074</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"> <widget class="QTabWidget" name="tabWidget"> <property name="geometry"> <rect> <x>-70</x> <y>70</y> <width>1631</width> <height>1071</height> </rect> </property> <property name="currentIndex"> <number>7</number> </property> <widget class="QWidget" name="tab"> <attribute name="title"> <string>Datenschauer</string> </attribute> <widget class="QTextEdit" name="textEdit"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>231</width> <height>621</height> </rect> </property> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Datenordner</p></body></html></string> </property> </widget> <widget class="QTextEdit" name="textEdit_2"> <property name="geometry"> <rect> <x>230</x> <y>0</y> <width>711</width> <height>641</height> </rect> </property> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">skript-editor</p></body></html></string> </property> </widget> </widget> <widget class="QWidget" name="tab_2"> <attribute name="title"> <string>Spielstart</string> </attribute> </widget> <widget class="QWidget" name="waren"> <attribute name="title"> <string>Waren/Stationen</string> </attribute> <widget class="QTextEdit" name="textEdit_3"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>211</width> <height>1111</height> </rect> </property> <property name="html"> <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Warenauswahl</p></body></html></string> </property> </widget> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>210</x> <y>0</y> <width>91</width> <height>16</height> </rect> </property> <property name="text"> <string>Warenname:</string> </property> </widget> <widget class="QLineEdit" name="lineEdit"> <property name="geometry"> <rect> <x>300</x> <y>0</y> <width>113</width> <height>25</height> </rect> </property> </widget> </widget> <widget class="QWidget" name="tab_3"> <attribute name="title"> <string>menu</string> </attribute> </widget> <widget class="QWidget" name="tab_4"> <attribute name="title"> <string>Software</string> </attribute> </widget> <widget class="QWidget" name="mb"> <attribute name="title"> <string>Mission-Aurträge</string> </attribute> </widget> <widget class="QWidget" name="tab_5"> <attribute name="title"> <string>schiff</string> </attribute> </widget> <widget class="QWidget" name="tab_6"> <attribute name="title"> <string>Faktionen</string> </attribute> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>121</width> <height>25</height> </rect> </property> <property name="text"> <string>Dateien einlesen</string> </property> <property name="autoDefault"> <bool>false</bool> </property> </widget> //anfang gehört in den slot code <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>0</x> <y>40</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>Faktion:</string> </property> </widget> <widget class="QLabel" name="label_3"> <property name="geometry"> <rect> <x>60</x> <y>40</y> <width>91</width> <height>17</height> </rect> </property> <property name="text"> <string>plutarch(id)</string> </property> </widget> <widget class="QLabel" name="label_4"> <property name="geometry"> <rect> <x>60</x> <y>60</y> <width>111</width> <height>17</height> </rect> </property> <property name="text"> <string>namen-nummer</string> </property> </widget> <widget class="QLabel" name="label_5"> <property name="geometry"> <rect> <x>170</x> <y>60</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_6"> <property name="geometry"> <rect> <x>60</x> <y>80</y> <width>101</width> <height>17</height> </rect> </property> <property name="text"> <string>Beschreibung</string> </property> </widget> <widget class="QLabel" name="label_7"> <property name="geometry"> <rect> <x>170</x> <y>80</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_8"> <property name="geometry"> <rect> <x>60</x> <y>100</y> <width>91</width> <height>17</height> </rect> </property> <property name="text"> <string>Kurzname</string> </property> </widget> <widget class="QLabel" name="label_9"> <property name="geometry"> <rect> <x>170</x> <y>100</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_10"> <property name="geometry"> <rect> <x>60</x> <y>120</y> <width>91</width> <height>17</height> </rect> </property> <property name="text"> <string>Hauptrasse</string> </property> </widget> <widget class="QLabel" name="label_11"> <property name="geometry"> <rect> <x>170</x> <y>120</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_12"> <property name="geometry"> <rect> <x>60</x> <y>140</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>Lizensen:</string> </property> </widget> <widget class="QLabel" name="label_13"> <property name="geometry"> <rect> <x>170</x> <y>140</y> <width>131</width> <height>17</height> </rect> </property> <property name="text"> <string>Lizensbeschreibung</string> </property> </widget> <widget class="QLabel" name="label_14"> <property name="geometry"> <rect> <x>310</x> <y>140</y> <width>111</width> <height>17</height> </rect> </property> <property name="text"> <string>namen-nummer</string> </property> </widget> <widget class="QLabel" name="label_15"> <property name="geometry"> <rect> <x>420</x> <y>140</y> <width>31</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_16"> <property name="geometry"> <rect> <x>460</x> <y>140</y> <width>151</width> <height>17</height> </rect> </property> <property name="text"> <string>Beschreibungsnummer</string> </property> </widget> <widget class="QLabel" name="label_17"> <property name="geometry"> <rect> <x>620</x> <y>140</y> <width>41</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_18"> <property name="geometry"> <rect> <x>660</x> <y>140</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>Ansehen:</string> </property> </widget> <widget class="QLabel" name="label_19"> <property name="geometry"> <rect> <x>730</x> <y>140</y> <width>31</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_20"> <property name="geometry"> <rect> <x>770</x> <y>140</y> <width>41</width> <height>17</height> </rect> </property> <property name="text"> <string>Preis</string> </property> </widget> <widget class="QLabel" name="label_21"> <property name="geometry"> <rect> <x>820</x> <y>140</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> <widget class="QLabel" name="label_22"> <property name="geometry"> <rect> <x>60</x> <y>160</y> <width>101</width> <height>17</height> </rect> </property> <property name="text"> <string>Beziehungen:</string> </property> </widget> <widget class="QLabel" name="label_23"> <property name="geometry"> <rect> <x>170</x> <y>160</y> <width>101</width> <height>17</height> </rect> </property> <property name="text"> <string>Faktionsname</string> </property> </widget> <widget class="QLabel" name="label_24"> <property name="geometry"> <rect> <x>280</x> <y>160</y> <width>64</width> <height>17</height> </rect> </property> <property name="text"> <string>int</string> </property> </widget> </widget> </widget> </widget> //ende gehört in den slotcode <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1376</width> <height>22</height> </rect> </property> <widget class="QMenu" name="menux_skripter"> <property name="title"> <string>x - skripter</string> </property> <addaction name="separator"/> <addaction name="actionload_data"/> </widget> <addaction name="menux_skripter"/> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> </widget> <widget class="QStatusBar" name="statusBar"/> <action name="actionload_data"> <property name="text"> <string>load data</string> </property> </action> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
Problem:
ich habe keine Ahnung wie ich den Code dynamisch (während der laufzeit)schlechte lösungsansetze:
- Ein extra programm schreiben das die GUI schreibt und dann das Programm neu gestartet bzw. compelieren.
-
@nagnag hi,
wenn du ein wenig tiefer nachsiehst, wirst du merken, dass die .ui von einem programm namens uic in eine Datei ui_xxx.h umgewandelt wird.
In dieser Datei steht dann der Code, der die UI erzeugt. Genauso kann eine UI auch rein per Programm erzeugt werden, bzw. gemischt per Designer und Programm.
Das ist aber alles gut dokumentiert bzw. wird auch in den Büchern abgehandelt.
Grüsse
-
danke für die Information hat mir gut geholfen.
Hab die bin-Dateien gefunden. Sie waren nicht in einem subverzeichnis so war es nicht gleich ofentsichtlich. Aber durch wahrloses klicken durch die qtcreatortabs hab ich es gefunden.
Ich weiß jetzt nicht wie ich Designer + Programm ins zusammenspiel kommt aber ich hab jetzt die ui_main.h geändert und werkel nun mich nun langsam durch die Makefile. so in ein paar Tage kann ich mehr sagen. -
Vielleicht zum Einstieg ganz gut: https://www.bogotobogo.com/Qt/Qt5_LayoutNotUsingDesigner.php
Ist in Englisch, sollte aber gut nachvollziehbar sein.