Thanks, it is running now without error message.
Tried out the first part of it. There were some things odd.
1. As the screen shoot (of exactly the first code block pasted below) shows: I could not make out, where to print it. When I execute in the console line by line: exactly nothing is printed.
2. referring to:
myWidget.resize(QtCore.QSize(300,100)) # sets size of the widget
label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size
I can not recognize that these lines do anything. See screen shot. They did not change the geometry at least as it seems.
3. When I block-execute 2.dode block in the console (c&p) only a empty window appairs.
Alltogether: I lack a clear expectation of, what should I expect from the code? What explicitly wants to demonstrate this tutorial?
Tia
Code: Select all
import time
import Draft
import sys
from PySide import QtGui
from PySide import QtCore #changed
app = QtGui.qApp
mw = FreeCADGui.getMainWindow()
myWidget = QtGui.QDockWidget()#changed
#mw = app.activeWindow()
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myWidget)
myWidget.setObjectName("my Nice New Widget")
#Where do I notice a difference?
myWidget.resize(QtCore.QSize(300,100)) # sets size of the widget
#Where do I notice a difference?
label = QtGui.QLabel("Hallo World", myWidget) # creates a label
label = QtGui.QLabel("Hllo Worlds", myWidget) # creates a label
##debug
#Gui.SendMsgToActiveView("ViewFit")
#Gui.activeDocument().activeView().viewAxometric()
#time.sleep(2)
#Gui.SendMsgToActiveView("ViewFit")
#Gui.activeDocument().activeView().viewAxometric()
##debug sleep
label = QtGui.QLabel("Hello Worldsss", myWidget) # creates a label
##W can not change it in the console
label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size
Code: Select all
class myWidget_Ui(object):
def setupUi(self, myWidget):
myWidget.setObjectName("my Nice New Widget")
myWidget.resize(QtCore.QSize(300,100).expandedTo(myWidget.minimumSizeHint())) # sets size of the widget
self.label = QtGui.QLabel(myWidget) # creates a label
self.label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size
self.label.setObjectName("label") # sets its name, so it can be found by name
def retranslateUi(self, draftToolbar): # built-in QT function that manages translations of widgets
myWidget.setWindowTitle(QtGui.QApplication.translate("myWidget", "My Widget", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("myWidget", "Welcome to my new widget!", None, QtGui.QApplication.UnicodeUTF8))
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget
myNewFreeCADWidget.ui = myWidget_Ui() # load the Ui script
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # setup the ui
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
#Error message tried instead:
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
#what has happened, what is it for?
#can not change the label afterwards in the console