PDA

View Full Version : Custom widget



zorro68
28th January 2008, 12:19
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:



editor1 = new QTextEdit;
editor2 = new QTextEdit;
editor3 = new QTextEdit;
splitter = new QSplitter (Qt::Horizontal,this);
splitter->addWidget(editor1);
splitter->addWidget(editor2);
splitter->addWidget(editor3);


and in the mainwindows i programm something like this:



CreateToolBars();
CreateStatusBar();

QWidget *w = new QWidget;
setCentralWidget(w);

TextEditor = new WindowsTextEditor(); //--->this is my custom widget
TextEditor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(TextEditor);
w->setLayout(vbox);


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:


TextEditor = new WindowsTextEditor(800,800);


and in my custom:


this->setGeometry(0,0,width,height);
editor1 = new QTextEdit;
...


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

Thanks

ashukla
28th January 2008, 12:27
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:



editor1 = new QTextEdit;
editor2 = new QTextEdit;
editor3 = new QTextEdit;
splitter = new QSplitter (Qt::Horizontal,this);
splitter->addWidget(editor1);
splitter->addWidget(editor2);
splitter->addWidget(editor3);


and in the mainwindows i programm something like this:



CreateToolBars();
CreateStatusBar();

QWidget *w = new QWidget;
setCentralWidget(w);

TextEditor = new WindowsTextEditor(); //--->this is my custom widget
TextEditor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(TextEditor);
w->setLayout(vbox);


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:


TextEditor = new WindowsTextEditor(800,800);


and in my custom:


this->setGeometry(0,0,width,height);
editor1 = new QTextEdit;
...


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

Thanks
Did you play with setFixedHeight() & setFixedWidth() for your custom widget.

zorro68
28th January 2008, 12:38
I have just tested this functions and not work, don't do nothing:


w->setFixedHeight(800);
w->setFixedWidth(800);

wysota
28th January 2008, 12:46
Could you provide a minimal compilable example reproducing the problem?

zorro68
28th January 2008, 13:17
I have been clean the programm.....

Here you are...

wysota
28th January 2008, 13:43
You didn't add the splitter into the widget's layout.

zorro68
28th January 2008, 14:08
I have just change the code of my custom widget constructor with (I think is that you are telling me):



editor1 = new QTextEdit;
editor2 = new QTextEdit;
editor3 = new QTextEdit;
splitter = new QSplitter (Qt::Horizontal);//--->change
splitter->addWidget(editor1);
splitter->addWidget(editor2);
splitter->addWidget(editor3);
QVBoxLayout *vbox = new QVBoxLayout; //new
vbox->addWidget(splitter); //new
this->setLayout(vbox); //new


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.

wysota
28th January 2008, 15:06
For me it seems your class is completely broken.

You should implement it like so:


#include <QtGui>

class X : public QSplitter {
public:
X() : QSplitter(Qt::Horizontal){
addWidget(new QTextEdit);
addWidget(new QTextEdit);
addWidget(new QTextEdit);
}

};

int main(int argc, char **argv){
QApplication app(argc, argv);
X edit;
edit.show();
return app.exec();
}