PDA

View Full Version : How to Promote QWebview (Custom widget)



Tadas
18th September 2010, 13:55
Hi,

I'm trying to recreate these tutorials:
http://labs.qt.nokia.com/2008/07/03/putting-qtwebkit-to-use-with-google-maps/
http://efforts.embedded.ufcg.edu.br/qt/?p=80

There is one thing I cant understand, how to promote QWebview.

I make identical class, project file, I only make custom Ui. but then I add QWebView to Ui, I can't promote it. Do I need edit mainwindow.ui manually ? as far as I know, this file is generated automatically by Qt Gui designer.
For example, I create Header file map.h (I will add functionality later)

#ifndef MAP_H
#define MAP_H
#include <QWebView>
class map : public QWebView
{
Q_OBJECT
public:
explicit map(QWidget *parent = 0);
signals:
public slots:
};
#endif // MAP_H

and source file map.cpp with class

#include "map.h"
#include "ui_mainwindow.h"

map::map(QWidget *parent) :
QWebView(parent)
{
}


then in UI designer "mainwindow.ui" I add QWebview Widget, Reneame Object name to "map", then I click on it right mouse button, but I can't see "Promote to" option.

other project files
mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}
untitled1.pro

QT += core gui

TARGET = untitled1
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
map.cpp

HEADERS += mainwindow.h \
map.h

FORMS += mainwindow.ui
QT+= network \
xml\
webkit


If I try to add promoted widget manually from menu "Promoted widgets..." in drop box "base class name:" I cant see QWebView

Thank you in advice.

wysota
18th September 2010, 22:13
It seems QWebView cannot be promoted with Designer.

Tadas
18th September 2010, 22:30
hi wysota,

but in these tutorials:
http://labs.qt.nokia.com/2008/07/03/...h-google-maps/
http://efforts.embedded.ufcg.edu.br/qt/?p=80
It is done, so there is some way. Both tutorials use Qt designer to develop ui.

wysota
18th September 2010, 22:44
http://efforts.embedded.ufcg.edu.br/qt/?p=82

Tadas
19th September 2010, 11:31
Thank you wysota,

That was my mistake, I could not find this link, but I have searched and tired many things, but never mind. Thank you for your time and answer.

I have changed wit text editor "mainwindow.ui" like below:

<?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>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWebView" name="webView">
<property name="geometry">
<rect>
<x>80</x>
<y>10</y>
<width>300</width>
<height>200</height>
</rect>
</property>
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>20</height>
</rect>
</property>
</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"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKit/QWebView</header>
</customwidget>
<customwidget>
<class>map</class>
<extends>QWebView</extends>
<header>map.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>


then I opened project with Qt Creator again, and I was able to promote QWebview.