PDA

View Full Version : Custom Widget :A class extending a Qwidget, I dont see anything...



tonnot
11th March 2011, 07:57
I want to have a custom widget extending, for example, a Qtreeview.
I dont want to reimplement paintevent, simply have some more functions.
Ok, I dont see anything when put my custom widget plugin on my form.
What is happen ?
Thanks

Lykurg
11th March 2011, 08:32
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!

How often do we have to tell, that we can not answer questions like
What is happen ?if you don't show us any line of code or describe that function do you have added and how.

tonnot
11th March 2011, 09:38
Ok, if you want here is the code, simply a skeleton.



#ifndef A_TABLE_H
#define A_TABLE_H
#include <QtGui/QTreeView>
#include <QObject>
class A_table : public QTreeView
{
Q_OBJECT

public:
A_table(QWidget *parent=0);
};
#endif // A_TABLE_H


#include "a_table.h"
A_table::A_table(QWidget *parent) : QTreeView()
{ }

Then, I choose a Qwidget, and promote to A_table.
When run the prog. I dont see nothing. A least, I have to see an empty white widget, isn't ?
Thanks

wysota
11th March 2011, 09:43
What does the constructor generated by uic for your program look like?

tonnot
11th March 2011, 09:52
Nothing , a transparent Widget. ....

However, I have another Qwidget that has paintevent and this one is viewed ok when run the prog.
So, I dont know If I must to override paintevent?
I only want, by the moment, to have a Qwidget that extends a Qt widget.
Thanks

SixDegrees
11th March 2011, 09:55
You have an empty widget because promotion doesn't incorporate your custom widget into Designer/Creator. To do that, you have to implement the correct plugin interface so the tool knows how to display your custom widget.

The empty widget provided by the promotion facility simply serves as a layout aid. When you preview or build, it will be replaced by an instance of your widget.

nish
11th March 2011, 09:56
have you tested your class in plain C++ instead of promoting and using the ui?

tonnot
11th March 2011, 10:18
1.- I have tested the class in 'old' style (creating the instance, givin size, etc) and It is showed. ( an empty white QTreeView)
2.- If I extend the A_table to Qpushbutton.... promote works fine, I see an empty space at my form, but I see a button when run. (so, it is ok).
So, finally, I cannot extend a basic QTreeView using promote ?

wysota
11th March 2011, 11:15
Nothing , a transparent Widget. ....
This is not an answer to my question. Again, please post code generated by uic for a form containing your promoted class.

tonnot
11th March 2011, 11:21
Here you are:

#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QTreeView>
#include <QtGui/QWidget>
#include <a_table.h>

QT_BEGIN_NAMESPACE

class Ui_MainWindow
{
public:
QWidget *centralWidget;
QPushButton *pushButton;
QLabel *label;
QLabel *label_2;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QLineEdit *lineEdit;
QPushButton *pushButton_4;
QPushButton *pushButton_5;
QLabel *label_tiempo;
QPushButton *pushButton_6;
QTreeView *treeView;
A_table *widget;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;

void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(568, 676);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(264, 24, 75, 23));
label = new QLabel(centralWidget);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(36, 12, 46, 13));
label_2 = new QLabel(centralWidget);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(204, 132, 46, 13));
pushButton_2 = new QPushButton(centralWidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(400, 120, 75, 23));
pushButton_3 = new QPushButton(centralWidget);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setGeometry(QRect(140, 160, 75, 23));
lineEdit = new QLineEdit(centralWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(20, 160, 113, 20));
pushButton_4 = new QPushButton(centralWidget);
pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
pushButton_4->setGeometry(QRect(480, 180, 75, 23));
pushButton_5 = new QPushButton(centralWidget);
pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
pushButton_5->setGeometry(QRect(20, 200, 75, 23));
label_tiempo = new QLabel(centralWidget);
label_tiempo->setObjectName(QString::fromUtf8("label_tiempo"));
label_tiempo->setGeometry(QRect(340, 120, 46, 13));
pushButton_6 = new QPushButton(centralWidget);
pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
pushButton_6->setGeometry(QRect(20, 280, 75, 23));
treeView = new QTreeView(centralWidget);
treeView->setObjectName(QString::fromUtf8("treeView"));
treeView->setGeometry(QRect(120, 211, 401, 161));
treeView->setAlternatingRowColors(true);
widget = new A_table(centralWidget);
widget->setObjectName(QString::fromUtf8("widget"));
widget->setGeometry(QRect(120, 400, 261, 141));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 568, 20));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);

retranslateUi(MainWindow);

QMetaObject::connectSlotsByName(MainWindow);
} // setupUi

void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("MainWindow", "PushButton", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("MainWindow", "abre fichero", 0, QApplication::UnicodeUTF8));
pushButton_3->setText(QApplication::translate("MainWindow", "buffer", 0, QApplication::UnicodeUTF8));
pushButton_4->setText(QApplication::translate("MainWindow", "bool", 0, QApplication::UnicodeUTF8));
pushButton_5->setText(QApplication::translate("MainWindow", "buffer", 0, QApplication::UnicodeUTF8));
label_tiempo->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
pushButton_6->setText(QApplication::translate("MainWindow", "memory", 0, QApplication::UnicodeUTF8));
} // retranslateUi

};

namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_MAINWINDOW_H

wysota
11th March 2011, 11:24
And if you build this file with a simple main(), you get a completely blank widget?


int main(int argc, char **argv){
QApplication app(argc, argv);
QMainWindow mw;
Ui::MainWindow ui;
ui.setupUi(&mw);
mw.show();
return app.exec();
}

tonnot
11th March 2011, 11:53
I test your code and I have nothing (a transparent widget)
But

1.- I have tested the class in 'old' style (creating the instance, givin size, etc) and It is showed. ( an empty white QTreeView)
2.- If I extend the A_table to Qpushbutton.... promote works fine, I see an empty space at my form, but I see a button when run. (so, it is ok).
So, finally, I cannot extend a basic QTreeView using promote ?


Thanks

wysota
11th March 2011, 11:58
Please attach a complete archive with all the source files of your test project.

tonnot
11th March 2011, 12:43
Here you are. If you see the code you can view the 'manually' added:

// This is 'manually' added.
tabla=new A_tabla;
tabla->setParent(ui->centralWidget);
tabla->setGeometry(20,20,100,100);
which works.
Thanks

wysota
11th March 2011, 12:47
Geeezzz tonnot.... you're missing layouts in your ui...

tonnot
11th March 2011, 12:53
Wysota, Why I need layouts ?
This is the reason because a Widget extending Qtreeview is not viewed using promote ?
And :


1.- I have tested the class in 'old' style (creating the instance, givin size, etc) and It is showed. ( an empty white QTreeView)
2.- If I extend the A_table to Qpushbutton.... promote works fine, I see an empty space at my form, but I see a button when run. (so, it is ok).
So, finally, I cannot extend a basic QTreeView using promote ?

Lykurg
11th March 2011, 12:57
Geeezzz tonnot.... you're missing layouts in your ui...
:confused: You sound surprised.

Ok, if you want here is the code, simply a skeleton.
[...]

#include "a_table.h"
A_table::A_table(QWidget *parent) : QTreeView()
{ }Yeah, an incomplete one. You might want to pass the parent to the base class... That's why you don't see anything.

tonnot
11th March 2011, 13:02
Ok, it works.
And, as a newbie, Why? A_table is already a Qobject....
Thanks

wysota
11th March 2011, 13:21
:confused: You sound surprised.
I am surprised. I thought that after writing 200 posts one would at least know how to use layouts. At times like this my hands fall down and I want to sit down and cry.