Results 1 to 19 of 19

Thread: Custom Widget :A class extending a Qwidget, I dont see anything...

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom Widget :A class extending a Qwidget, I dont see anything...

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!

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

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

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


    Qt Code:
    1. #ifndef A_TABLE_H
    2. #define A_TABLE_H
    3. #include <QtGui/QTreeView>
    4. #include <QObject>
    5. class A_table : public QTreeView
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. A_table(QWidget *parent=0);
    11. };
    12. #endif // A_TABLE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "a_table.h"
    2. A_table::A_table(QWidget *parent) : QTreeView()
    3. { }
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    What does the constructor generated by uic for your program look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    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

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    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.

  7. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    have you tested your class in plain C++ instead of promoting and using the ui?

  8. #8
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    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 ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Quote Originally Posted by tonnot View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Here you are:
    Qt Code:
    1. #ifndef UI_MAINWINDOW_H
    2. #define UI_MAINWINDOW_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QHeaderView>
    9. #include <QtGui/QLabel>
    10. #include <QtGui/QLineEdit>
    11. #include <QtGui/QMainWindow>
    12. #include <QtGui/QMenuBar>
    13. #include <QtGui/QPushButton>
    14. #include <QtGui/QStatusBar>
    15. #include <QtGui/QToolBar>
    16. #include <QtGui/QTreeView>
    17. #include <QtGui/QWidget>
    18. #include <a_table.h>
    19.  
    20. QT_BEGIN_NAMESPACE
    21.  
    22. class Ui_MainWindow
    23. {
    24. public:
    25. QWidget *centralWidget;
    26. QPushButton *pushButton;
    27. QLabel *label;
    28. QLabel *label_2;
    29. QPushButton *pushButton_2;
    30. QPushButton *pushButton_3;
    31. QLineEdit *lineEdit;
    32. QPushButton *pushButton_4;
    33. QPushButton *pushButton_5;
    34. QLabel *label_tiempo;
    35. QPushButton *pushButton_6;
    36. QTreeView *treeView;
    37. A_table *widget;
    38. QMenuBar *menuBar;
    39. QToolBar *mainToolBar;
    40. QStatusBar *statusBar;
    41.  
    42. void setupUi(QMainWindow *MainWindow)
    43. {
    44. if (MainWindow->objectName().isEmpty())
    45. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    46. MainWindow->resize(568, 676);
    47. centralWidget = new QWidget(MainWindow);
    48. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    49. pushButton = new QPushButton(centralWidget);
    50. pushButton->setObjectName(QString::fromUtf8("pushButton"));
    51. pushButton->setGeometry(QRect(264, 24, 75, 23));
    52. label = new QLabel(centralWidget);
    53. label->setObjectName(QString::fromUtf8("label"));
    54. label->setGeometry(QRect(36, 12, 46, 13));
    55. label_2 = new QLabel(centralWidget);
    56. label_2->setObjectName(QString::fromUtf8("label_2"));
    57. label_2->setGeometry(QRect(204, 132, 46, 13));
    58. pushButton_2 = new QPushButton(centralWidget);
    59. pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    60. pushButton_2->setGeometry(QRect(400, 120, 75, 23));
    61. pushButton_3 = new QPushButton(centralWidget);
    62. pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
    63. pushButton_3->setGeometry(QRect(140, 160, 75, 23));
    64. lineEdit = new QLineEdit(centralWidget);
    65. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    66. lineEdit->setGeometry(QRect(20, 160, 113, 20));
    67. pushButton_4 = new QPushButton(centralWidget);
    68. pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
    69. pushButton_4->setGeometry(QRect(480, 180, 75, 23));
    70. pushButton_5 = new QPushButton(centralWidget);
    71. pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
    72. pushButton_5->setGeometry(QRect(20, 200, 75, 23));
    73. label_tiempo = new QLabel(centralWidget);
    74. label_tiempo->setObjectName(QString::fromUtf8("label_tiempo"));
    75. label_tiempo->setGeometry(QRect(340, 120, 46, 13));
    76. pushButton_6 = new QPushButton(centralWidget);
    77. pushButton_6->setObjectName(QString::fromUtf8("pushButton_6"));
    78. pushButton_6->setGeometry(QRect(20, 280, 75, 23));
    79. treeView = new QTreeView(centralWidget);
    80. treeView->setObjectName(QString::fromUtf8("treeView"));
    81. treeView->setGeometry(QRect(120, 211, 401, 161));
    82. treeView->setAlternatingRowColors(true);
    83. widget = new A_table(centralWidget);
    84. widget->setObjectName(QString::fromUtf8("widget"));
    85. widget->setGeometry(QRect(120, 400, 261, 141));
    86. MainWindow->setCentralWidget(centralWidget);
    87. menuBar = new QMenuBar(MainWindow);
    88. menuBar->setObjectName(QString::fromUtf8("menuBar"));
    89. menuBar->setGeometry(QRect(0, 0, 568, 20));
    90. MainWindow->setMenuBar(menuBar);
    91. mainToolBar = new QToolBar(MainWindow);
    92. mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
    93. MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
    94. statusBar = new QStatusBar(MainWindow);
    95. statusBar->setObjectName(QString::fromUtf8("statusBar"));
    96. MainWindow->setStatusBar(statusBar);
    97.  
    98. retranslateUi(MainWindow);
    99.  
    100. QMetaObject::connectSlotsByName(MainWindow);
    101. } // setupUi
    102.  
    103. void retranslateUi(QMainWindow *MainWindow)
    104. {
    105. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
    106. pushButton->setText(QApplication::translate("MainWindow", "PushButton", 0, QApplication::UnicodeUTF8));
    107. label->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
    108. label_2->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
    109. pushButton_2->setText(QApplication::translate("MainWindow", "abre fichero", 0, QApplication::UnicodeUTF8));
    110. pushButton_3->setText(QApplication::translate("MainWindow", "buffer", 0, QApplication::UnicodeUTF8));
    111. pushButton_4->setText(QApplication::translate("MainWindow", "bool", 0, QApplication::UnicodeUTF8));
    112. pushButton_5->setText(QApplication::translate("MainWindow", "buffer", 0, QApplication::UnicodeUTF8));
    113. label_tiempo->setText(QApplication::translate("MainWindow", "TextLabel", 0, QApplication::UnicodeUTF8));
    114. pushButton_6->setText(QApplication::translate("MainWindow", "memory", 0, QApplication::UnicodeUTF8));
    115. } // retranslateUi
    116.  
    117. };
    118.  
    119. namespace Ui {
    120. class MainWindow: public Ui_MainWindow {};
    121. } // namespace Ui
    122.  
    123. QT_END_NAMESPACE
    124.  
    125. #endif // UI_MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    And if you build this file with a simple main(), you get a completely blank widget?

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. Ui::MainWindow ui;
    4. ui.setupUi(&mw);
    5. mw.show();
    6. return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    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

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Please attach a complete archive with all the source files of your test project.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Here you are. If you see the code you can view the 'manually' added:
    Qt Code:
    1. // This is 'manually' added.
    2. tabla=new A_tabla;
    3. tabla->setParent(ui->centralWidget);
    4. tabla->setGeometry(20,20,100,100);
    To copy to clipboard, switch view to plain text mode 
    which works.
    Thanks
    Attached Files Attached Files

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Geeezzz tonnot.... you're missing layouts in your ui...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    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 ?

  17. #17
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Quote Originally Posted by wysota View Post
    Geeezzz tonnot.... you're missing layouts in your ui...
    You sound surprised.
    Quote Originally Posted by tonnot View Post
    Ok, if you want here is the code, simply a skeleton.
    [...]
    Qt Code:
    1. #include "a_table.h"
    2. A_table::A_table(QWidget *parent) : QTreeView()
    3. { }
    To copy to clipboard, switch view to plain text mode 
    Yeah, an incomplete one. You might want to pass the parent to the base class... That's why you don't see anything.

  18. #18
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Ok, it works.
    And, as a newbie, Why? A_table is already a Qobject....
    Thanks

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Widget :A class extending a Qwidget, I dont see anything...

    Quote Originally Posted by Lykurg View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QWidget -> updateGeometry dont work.
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 22nd May 2013, 15:55
  2. Replies: 7
    Last Post: 1st March 2011, 23:02
  3. Replies: 1
    Last Post: 10th February 2011, 16:16
  4. Replies: 3
    Last Post: 28th January 2010, 09:15
  5. Replies: 0
    Last Post: 3rd January 2009, 05:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.