Results 1 to 8 of 8

Thread: QHBoxLayout

  1. #1
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QHBoxLayout

    I am doing the following to add my class (directX) in a QHBoxLayout:

    Qt Code:
    1. Window::Window(QWidget* parent)
    2. : QWidget(0) // top-level, no parent
    3. {
    4. ui.setupUi(this);
    5.  
    6. QHBoxLayout *layout = new QHBoxLayout();
    7. setLayout(layout);
    8. layout->addWidget(new QD3DWidget(this));
    9. }
    To copy to clipboard, switch view to plain text mode 

    Everything works perfectly, but would like to use the QT Designer,
    So I created a QHBoxLayout but I can not add in my QD3DWidget QHBoxLayout, I'm trying something like:
    Qt Code:
    1. Window::Window(QWidget* parent)
    2. : QWidget(0) // top-level, no parent
    3. {
    4. ui.setupUi(this);
    5.  
    6. ui.horizontalLayout->addWidget(new QD3DWidget(this));
    7. }
    To copy to clipboard, switch view to plain text mode 

    The viewport directx does not appear, only a white window appears, and I set to be blue in directX,and when I make the code directly (without ui) it is blue

    Thanks

  2. #2
    Join Date
    Dec 2010
    Location
    Omaha, NE
    Posts
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHBoxLayout

    Go into the generated ui file (probably ui_Window.h) to see what the difference is between that and your coded creation of the layout. This is how I usually figure out how to code something up that I can only get to work from designer. Something must be different between the two if they work differently...

  3. #3
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QHBoxLayout

    my ui_Main.h
    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'Main.ui'
    3. **
    4. ** Created: Sat 4. Dec 17:22:16 2010
    5. ** by: Qt User Interface Compiler version 4.7.1
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_MAIN_H
    11. #define UI_MAIN_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QHBoxLayout>
    18. #include <QtGui/QHeaderView>
    19. #include <QtGui/QWidget>
    20.  
    21. QT_BEGIN_NAMESPACE
    22.  
    23. class Ui_Form
    24. {
    25. public:
    26. QWidget *horizontalLayoutWidget;
    27. QHBoxLayout *horizontalLayout;
    28.  
    29. void setupUi(QWidget *Form)
    30. {
    31. if (Form->objectName().isEmpty())
    32. Form->setObjectName(QString::fromUtf8("Form"));
    33. Form->resize(909, 711);
    34. horizontalLayoutWidget = new QWidget(Form);
    35. horizontalLayoutWidget->setObjectName(QString::fromUtf8("horizontalLayoutWidget"));
    36. horizontalLayoutWidget->setGeometry(QRect(90, 209, 381, 351));
    37. horizontalLayout = new QHBoxLayout(horizontalLayoutWidget);
    38. horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    39. horizontalLayout->setContentsMargins(0, 0, 0, 0);
    40.  
    41. retranslateUi(Form);
    42.  
    43. QMetaObject::connectSlotsByName(Form);
    44. } // setupUi
    45.  
    46. void retranslateUi(QWidget *Form)
    47. {
    48. Form->setWindowTitle(QApplication::translate("Form", "Form", 0, QApplication::UnicodeUTF8));
    49. } // retranslateUi
    50.  
    51. };
    52.  
    53. namespace Ui {
    54. class Form: public Ui_Form {};
    55. } // namespace Ui
    56.  
    57. QT_END_NAMESPACE
    58.  
    59. #endif // UI_MAIN_H
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QHBoxLayout

    anyone?

  5. #5
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QHBoxLayout

    As the window, I am creating in QtDesigner:


    Using the ui, the code looks like, and the window when run like this:
    Qt Code:
    1. Window::Window(QWidget* parent)
    2. : QWidget(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. ui.horizontalLayout->addWidget(new QD3DWidget());
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 


    And when I create my QHBoxLayout the code looks like this:
    Qt Code:
    1. Window::Window(QWidget* parent)
    2. : QWidget(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6.  
    7. QHBoxLayout *layout = new QHBoxLayout();
    8. setLayout(layout);
    9. layout->addWidget(new QD3DWidget());
    10. }
    To copy to clipboard, switch view to plain text mode 


    A note: The blue screen means that the code of DirectX is working, I configured it to clean the screen with the color blue

    and using the code (last image), so if I do (wrong):
    Qt Code:
    1. layout->addWidget(new QD3DWidget()); //not using this
    To copy to clipboard, switch view to plain text mode 
    it is white
    and if I do so, it turns blue (correct):
    Qt Code:
    1. layout->addWidget(new QD3DWidget(this)); //using this
    To copy to clipboard, switch view to plain text mode 

    Thanks

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QHBoxLayout

    If you do not set the parent of the widget you are inserting into the layout then it cannot appear as a child of the form widget. A widget without a parent is a top-level window regardless of which layouts you add it to. It doesn't show because it has not inherited the visibility of its parent (it doesn't have one).

    To do this with Designer:


    BTW: The layout you have dropped into your QWidget in Designer is unused.

  7. The following user says thank you to ChrisW67 for this useful post:

    VitaliBR (6th December 2010)

  8. #7
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QHBoxLayout

    thanks guy!! worked perfectly

    Only want to know how to access the methods of my class QD3DWidget

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QHBoxLayout

    The same way you access the methods of any other widget in the UI. It varies with how you have incorporated the Designer generated code, but generally:
    Qt Code:
    1. ui->myWidget->myWidgetMethod();
    2. or
    3. ui.myWidget->myWidgetMethod();
    To copy to clipboard, switch view to plain text mode 
    The generated code will include the headers you specified when you promoted the QWidget, making your widget's methods known.

  10. The following user says thank you to ChrisW67 for this useful post:

    VitaliBR (6th December 2010)

Similar Threads

  1. QHBoxLayout & QVBoxLayout
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 15:13
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 08:57
  3. zero'ing margin in a qhboxlayout
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 11:54
  4. QHBoxLayout Problem
    By Seema Rao in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2006, 16:51
  5. Replies: 3
    Last Post: 19th April 2006, 21:53

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.