1 Attachment(s)
Help needed in adding QWidget and other objects to a QHBoxLayout
I am using Qt 3.3.5 and trying to emulate how the Acrobat PDF viewer works i.e. to view thumbnails of a document loaded.
The enclosed attachment details the layout I need.
Scenario
I have a 'MainWindowBase' in which I :
- created 2 toolbars, one on top, and a left toolbar.
- The main window loads a 'document' which I can navigate just like Acrobat. All this works fine.
I want to add:
A column (QListBox) to the left of the document, this will contain the thumbnails of the document (a la Acrobat viewer).
Code
I can't see QWidget lsited under 'Containers'in my QtDesigner, hence I am creating one at runtime. My code is as follows:
Code:
// ListBox for thumbnail sidebar
QListBox *thbNailListBox = new QListBox();
//thbNailListBox->setEnabled(true);
//thbNailListBox->setGeometry(10,10,50,100);
mainHLayout->add(thbNailListBox);
mainHLayout->addWidget(documentView); // documentView is the 'Document' object
setCentralWidget ( mainWidget );
Problem
- I don't see the QListBox and the 'documentView' is not visible at the extreme top left corner
- While using QHBoxLayout, to view the toolbars I need to put spacing = 25, if not the toolbars are covered by the mainWidget
- But using spacing = 25, makes the window look ackward as there is an extra spacing of 25 on the right as well as bottom of the main window
- How can I add a QWidget to the QtDesigner?
Could anyone suggest how best I can go about with this.
Any pointers will be appreciated.
Thanks,
1 Attachment(s)
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Quote:
Originally Posted by
qtUser500
I am using Qt 3.3.5
Ouch :) Can you consider upgrading to Qt 4.4.3?
Quote:
I can't see QWidget lsited under 'Containers'in my QtDesigner, hence I am creating one at runtime.
What do you need QWidget for? In your case I would recommend using QSplitter and this one is available in Designer from the layout toolbar. If you use it, you'll be able to point and click everything in Designer. Without the splitter you can do that too - I'm not sure what do you need the pure QWidget for. For the "document view" insert some widget like QFrame and promote it you your class by right clicking it and choosing "Promote to".
Quote:
While using QHBoxLayout, to view the toolbars I need to put spacing = 25, if not the toolbars are covered by the mainWidget
Either you have done something wrong or... no, there is no "or"... this shouldn't happen by itself.
Here is something I created quickly in Designer, maybe it will be helpful for you. It's probably not perfect, I haven't been using Qt3 Designer for over two years :)
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Thanks wysota for the quick reply, and for the .ui file
1. Unfortunately I have to use 3.3.5 as I need to enhance an old project that was developed using 3.3.5
2. QWidget was the one I was working with, I don't mind using any other widget or approach to be able to emulate the 'toggling' feature for thumbnail view(QListBox) of a document
3. I don't see QSplitter in my QtDesigner :(
4. Though I can create a frame, there is no 'Promote to' option when I right click it .
I really appreciate your feedback ... as I am going round in circles, trying to get this feature together, while hitting roadblocks everytime...am I limited because of qt 3.3.5? is there any possible workaround to get it to work .... please advise.
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Quote:
Originally Posted by
qtUser500
I can't see QWidget lsited under 'Containers'in my QtDesigner, hence I am creating one at runtime.
QWidget isn't exactly a container. It is the base class for all of Qt's graphical, well, widgets... But a QWidget itself doesn't have any special appearance, hence it's pointless to put a pure QWidget in an application.
And you should really consider using a newer version of Qt. Qt3 is neither maintained nor supported nor... well, anything at all... Qt4 is the way to go, Qt3 has been abandoned for a few years now.
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Quote:
Originally Posted by
qtUser500
1. Unfortunately I have to use 3.3.5 as I need to enhance an old project that was developed using 3.3.5
Too bad, it'd be much simpler in Qt4.
Quote:
3. I don't see QSplitter in my QtDesigner :(
It's there. But not in the widget toolbox but in the layout toolbar to the right of the grid layout icon. Select two widgets (like the listbox and the frame) and the icon will become active.
Quote:
4. Though I can create a frame, there is no 'Promote to' option when I right click it .
Right, sorry... the mechanism is a bit different in Qt3. Go to Tools->Custom->Edit custom widgets. If you fill the form that opens, the widget of your choice will become available in the "Custom" section of the widget toolbox.
Quote:
I really appreciate your feedback ... as I am going round in circles, trying to get this feature together, while hitting roadblocks everytime...
Don't worry, you'll manage to do it.
Quote:
am I limited because of qt 3.3.5?
Qt3 technology is about 10 years old. Much has happened since then. What you want to achieve would take about 10-15 minutes for a skilled Qt4 programmer.
Quote:
is there any possible workaround to get it to work .... please advise.
You don't have to work around anything. It's just more work in Qt3 than in Qt4 as the latter contains some components that would ease your job. Still the task is relatively easy just don't overcomplicate things. Try working on the form I gave you, it practically contains everything you need.
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Rexi: Thanks for the QWidget information .
wysota: Appreciate your detailed reply. :)
- I tried out what you suggested in Ur .ui, and was able to create the QSplitter (Horizontal) with the QListBox and the QFrame.:D
- I also put the layout of mainWindowBase to Horizontal, so that the QListBox and the QFrame resize when the window is resized
Questions (The last ones I promise ;))
I am trying to add the documentView at runtime. I get it to appear, but not in the appropriate way. This is what I did:
- Create a Layout, add the documentView to the layout, setLayout to the QFrame. But when I do this I see the documentView on the extreme left partially covering the side toolbar. The code is:
Code:
docLayout->add(documentView); // 'documentView' is the object I want in the layout and eventually in the QFrame
I actually don't need a horozontal/ vertical layout as the 'documentView' object is the only one I want in the QFrame. But I get an error when I try to use QLayout()
:( I am near and yet so far ...Please suggest how I can dynamically add the document view without the layout being skewed... thanks in advance wysota !
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Use addWidget() and not add().
1 Attachment(s)
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Thanks wysota , but addWidget too doesn't work. :(
Please see the enclosed screenshot when I used 'addWidget'.
The document View is displayed at the extreme top left corner.
Thanks!
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
It seems it is not added to the layout. Can you provide a larger snippet of code I might have a look at? Especially what you do with docFrame and what documentView is.
1 Attachment(s)
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Due to code confidentiality I unfortunately can't reveal the exact details but I have attached the skeleton .ui file, removing most of the toolbar actions. The rest of the layout in the UI is as is. Note that I have used Qt 3.3.5
docFrame: After adding it in the UI, I only access it when setting the layout for the frame ie.
documentView:
Code:
documentView
= new ViewClass
(QWidget*,
QString);
// Changed due to propriety reasons
Thanks for UR time wyosa, it is really appreciated!
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Well... unfortunately this doesn't say much more than what you already told us. Believe me, I've seen thousands of Qt object construction snippets. I'm sure yours is as standard as any else and won't reveal any sensitive information. I'm not asking about any logic, just the user interface creation code. What is the base class of "documentView"? Also please use addWidget() instead of add() even if the latter compiles. Also why don't you get rid of the frame and use the custom widget approach I suggested earlier? It would make your problem disappear right away as Qt would build the proper layout code for you.
Re: Help needed in adding QWidget and other objects to a QHBoxLayout
Thanks wysota, I was able to fix the issue. It was in the constructor of the documentView, I had to set the docFrame as the parent.
Thank you for all your time! :)