Hello!
I have a question, I want to display a PDF in one tab of my QTabWidget. Is this possible?
If I try
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
web = QWebView()
web.settings().setAttribute(QWebSettings.PluginsEnabled, True)
web.show()
web.
load(QUrl('test.pdf')) # Change path to actual file.sys.exit(app.exec_())
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.settings().setAttribute(QWebSettings.PluginsEnabled, True)
web.show()
web.load(QUrl('test.pdf')) # Change path to actual file.
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
everything works as expected.
If I add a QWebView to a tab, the PDF is not displayed:
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtWebKit import*
import sys
def main():
web = QWebView()
web.settings().setAttribute(QWebSettings.PluginsEnabled, True)
web.
load(QtCore.
QUrl('file:///test.pdf'))
#vBoxlayout.addWidget(pushButton2)
vBoxlayout.addWidget(web)
vBoxlayout.addWidget(pushButton1)
#Resize width and height
tabs.resize(250, 150)
#Move QTabWidget to x:300,y:300
tabs.move(300, 300)
#Set Layout for Third Tab Page
tab1.setLayout(vBoxlayout)
tabs.addTab(tab1,"Tab 1")
tabs.addTab(tab2,"Tab 2")
tabs.addTab(tab3,"Tab 3")
tabs.setWindowTitle('PyQt QTabWidget Add Tabs and Widgets Inside Tab')
tabs.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtWebKit import*
import sys
def main():
app = QtGui.QApplication(sys.argv)
tabs = QtGui.QTabWidget()
pushButton1 = QtGui.QPushButton("QPushButton 1")
pushButton2 = QtGui.QPushButton("QPushButton 2")
web = QWebView()
web.settings().setAttribute(QWebSettings.PluginsEnabled, True)
web.load(QtCore.QUrl('file:///test.pdf'))
tab1 = QtGui.QWidget()
tab2 = QtGui.QWidget()
tab3 = QtGui.QWidget()
vBoxlayout = QtGui.QVBoxLayout()
#vBoxlayout.addWidget(pushButton2)
vBoxlayout.addWidget(web)
vBoxlayout.addWidget(pushButton1)
#Resize width and height
tabs.resize(250, 150)
#Move QTabWidget to x:300,y:300
tabs.move(300, 300)
#Set Layout for Third Tab Page
tab1.setLayout(vBoxlayout)
tabs.addTab(tab1,"Tab 1")
tabs.addTab(tab2,"Tab 2")
tabs.addTab(tab3,"Tab 3")
tabs.setWindowTitle('PyQt QTabWidget Add Tabs and Widgets Inside Tab')
tabs.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
To copy to clipboard, switch view to plain text mode
Can anybody tell me what I am doing wrong?
Thanks in advance!
Stefanie
Bookmarks