Results 1 to 8 of 8

Thread: Custom widget

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Custom widget

    I'm trying to programm an qt application, and my design is the following. I need a menubar, toolbar, statusbar and the central widget. In the central widget i need to change among some custom widgets. Till now i have not problem. But when i programm my custom widget and try to put in the centralwidget, my customwidget not resize. Now i'm testing with a simple custom widget that contains 3 textboxes:

    Qt Code:
    1. editor1 = new QTextEdit;
    2. editor2 = new QTextEdit;
    3. editor3 = new QTextEdit;
    4. splitter = new QSplitter (Qt::Horizontal,this);
    5. splitter->addWidget(editor1);
    6. splitter->addWidget(editor2);
    7. splitter->addWidget(editor3);
    To copy to clipboard, switch view to plain text mode 

    and in the mainwindows i programm something like this:

    Qt Code:
    1. CreateToolBars();
    2. CreateStatusBar();
    3.  
    4. QWidget *w = new QWidget;
    5. setCentralWidget(w);
    6.  
    7. TextEditor = new WindowsTextEditor(); //--->this is my custom widget
    8. TextEditor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    9. vbox->addWidget(TextEditor);
    10. w->setLayout(vbox);
    To copy to clipboard, switch view to plain text mode 

    This paint the toolbar, menubar, statusbar and in the central widget puts a little box....
    I have tryed to give size to my widget, like this:
    Qt Code:
    1. TextEditor = new WindowsTextEditor(800,800);
    To copy to clipboard, switch view to plain text mode 

    and in my custom:
    Qt Code:
    1. this->setGeometry(0,0,width,height);
    2. editor1 = new QTextEdit;
    3. ...
    To copy to clipboard, switch view to plain text mode 

    But do the same, a little textbox....
    Someone knows what's happening?

    Thanks

  2. #2
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Custom widget

    Quote Originally Posted by zorro68 View Post
    I'm trying to programm an qt application, and my design is the following. I need a menubar, toolbar, statusbar and the central widget. In the central widget i need to change among some custom widgets. Till now i have not problem. But when i programm my custom widget and try to put in the centralwidget, my customwidget not resize. Now i'm testing with a simple custom widget that contains 3 textboxes:

    Qt Code:
    1. editor1 = new QTextEdit;
    2. editor2 = new QTextEdit;
    3. editor3 = new QTextEdit;
    4. splitter = new QSplitter (Qt::Horizontal,this);
    5. splitter->addWidget(editor1);
    6. splitter->addWidget(editor2);
    7. splitter->addWidget(editor3);
    To copy to clipboard, switch view to plain text mode 

    and in the mainwindows i programm something like this:

    Qt Code:
    1. CreateToolBars();
    2. CreateStatusBar();
    3.  
    4. QWidget *w = new QWidget;
    5. setCentralWidget(w);
    6.  
    7. TextEditor = new WindowsTextEditor(); //--->this is my custom widget
    8. TextEditor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    9. vbox->addWidget(TextEditor);
    10. w->setLayout(vbox);
    To copy to clipboard, switch view to plain text mode 

    This paint the toolbar, menubar, statusbar and in the central widget puts a little box....
    I have tryed to give size to my widget, like this:
    Qt Code:
    1. TextEditor = new WindowsTextEditor(800,800);
    To copy to clipboard, switch view to plain text mode 

    and in my custom:
    Qt Code:
    1. this->setGeometry(0,0,width,height);
    2. editor1 = new QTextEdit;
    3. ...
    To copy to clipboard, switch view to plain text mode 

    But do the same, a little textbox....
    Someone knows what's happening?

    Thanks
    Did you play with setFixedHeight() & setFixedWidth() for your custom widget.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  3. #3
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom widget

    I have just tested this functions and not work, don't do nothing:
    Qt Code:
    1. w->setFixedHeight(800);
    2. w->setFixedWidth(800);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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

    Could you provide a minimal compilable example reproducing the problem?

  5. #5
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom widget

    I have been clean the programm.....

    Here you are...
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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

    You didn't add the splitter into the widget's layout.

  7. #7
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom widget

    I have just change the code of my custom widget constructor with (I think is that you are telling me):

    Qt Code:
    1. editor1 = new QTextEdit;
    2. editor2 = new QTextEdit;
    3. editor3 = new QTextEdit;
    4. splitter = new QSplitter (Qt::Horizontal);//--->change
    5. splitter->addWidget(editor1);
    6. splitter->addWidget(editor2);
    7. splitter->addWidget(editor3);
    8. QVBoxLayout *vbox = new QVBoxLayout; //new
    9. vbox->addWidget(splitter); //new
    10. this->setLayout(vbox); //new
    To copy to clipboard, switch view to plain text mode 

    And the box is bigger but only shows one white box (text editor) and can't do anything in it (can't write....), and the box do not resize when i resize the mainwindow.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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

    For me it seems your class is completely broken.

    You should implement it like so:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class X : public QSplitter {
    4. public:
    5. X() : QSplitter(Qt::Horizontal){
    6. addWidget(new QTextEdit);
    7. addWidget(new QTextEdit);
    8. addWidget(new QTextEdit);
    9. }
    10.  
    11. };
    12.  
    13. int main(int argc, char **argv){
    14. QApplication app(argc, argv);
    15. X edit;
    16. edit.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  2. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  3. Custom tab widget question
    By PrimeCP in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 11:17
  4. Problem applying setWindowOpacity to a custom Widget
    By yellowmat in forum Qt Programming
    Replies: 8
    Last Post: 1st November 2006, 10:05
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

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.