I recently created a web browser with PyQt4 however when I try to insert an image background it displays black instead:
This complete code is here below: I tried using QPallete and SetStyleSheet methods, same problem.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(1269, 670)
MainWindow.setAutoFillBackground(True)
palette2 = QtGui.QPalette()
palette2.setBrush(QtGui.QPalette.Background, QtGui.QBrush(QtGui.QPixmap("bg.jpg")))
MainWindow.setPalette(palette2)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tb_back = QtGui.QToolButton(self.centralwidget)
self.tb_back.setGeometry(QtCore.QRect(10, 20, 41, 31))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/icons/back.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tb_back.setIcon(icon)
self.tb_back.setIconSize(QtCore.QSize(32, 32))
self.tb_back.setObjectName(_fromUtf8("tb_back"))
self.tb_reload = QtGui.QToolButton(self.centralwidget)
self.tb_reload.setGeometry(QtCore.QRect(60, 20, 41, 31))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/icons/reload.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tb_reload.setIcon(icon1)
self.tb_reload.setIconSize(QtCore.QSize(32, 32))
self.tb_reload.setObjectName(_fromUtf8("tb_reload"))
self.tb_forword_2 = QtGui.QToolButton(self.centralwidget)
self.tb_forword_2.setGeometry(QtCore.QRect(110, 20, 41, 31))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/icons/forword.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tb_forword_2.setIcon(icon2)
self.tb_forword_2.setIconSize(QtCore.QSize(32, 32))
self.tb_forword_2.setObjectName(_fromUtf8("tb_forword_2"))
self.tb_home = QtGui.QToolButton(self.centralwidget)
self.tb_home.setGeometry(QtCore.QRect(160, 20, 41, 31))
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/icons/home.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tb_home.setIcon(icon3)
self.tb_home.setIconSize(QtCore.QSize(32, 32))
self.tb_home.setObjectName(_fromUtf8("tb_home"))
self.ln_addressbar = QtGui.QLineEdit(self.centralwidget)
self.ln_addressbar.setGeometry(QtCore.QRect(210, 20, 491, 31))
self.ln_addressbar.setObjectName(_fromUtf8("ln_addressbar"))
self.ln_addressbar.editingFinished.connect(self.OnEditingFinished)
self.tb_search = QtGui.QToolButton(self.centralwidget)
self.tb_search.setGeometry(QtCore.QRect(710, 20, 41, 31))
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(_fromUtf8(":/icons/icons/search.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.tb_search.setIcon(icon4)
self.tb_search.setIconSize(QtCore.QSize(32, 32))
self.tb_search.setObjectName(_fromUtf8("tb_search"))
self.webView = QtWebKit.QWebView(self.centralwidget)
self.webView.setGeometry(QtCore.QRect(0, 60, 1261, 591))
self.webView.setStyleSheet("background: transparent")
self.webView.setUrl(QtCore.QUrl(_fromUtf8("https://www.google.ca")))
self.webView.setObjectName(_fromUtf8("webView"))
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Neel\'s Web Browser", None))
self.tb_back.setText(_translate("MainWindow", "...", None))
self.tb_reload.setText(_translate("MainWindow", "...", None))
self.tb_forword_2.setText(_translate("MainWindow", "...", None))
self.tb_home.setText(_translate("MainWindow", "...", None))
self.tb_search.setText(_translate("MainWindow", "...", None))
def OnEditingFinished(self):
self.webView.setUrl(QtCore.QUrl("http://"+self.ln_addressbar.text()))
print("User has visited:" + self.ln_addressbar.text())
from PyQt4 import QtWebKit
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Aucun commentaire:
Enregistrer un commentaire