Results 1 to 12 of 12

Thread: Help needed in adding QWidget and other objects to a QHBoxLayout

  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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 :
    1. created 2 toolbars, one on top, and a left toolbar.
    2. 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:
    Qt Code:
    1. QWidget *mainWidget = new QWidget;
    2. QHBoxLayout* mainHLayout = new QHBoxLayout( mainWidget, 25, 0);
    3.  
    4. // ListBox for thumbnail sidebar
    5. QListBox *thbNailListBox = new QListBox();
    6. //thbNailListBox->setEnabled(true);
    7. //thbNailListBox->setGeometry(10,10,50,100);
    8. mainHLayout->add(thbNailListBox);
    9. mainHLayout->addWidget(documentView); // documentView is the 'Document' object
    10.  
    11. setCentralWidget ( mainWidget );
    To copy to clipboard, switch view to plain text mode 


    Problem
    1. I don't see the QListBox and the 'documentView' is not visible at the extreme top left corner
    2. While using QHBoxLayout, to view the toolbars I need to put spacing = 25, if not the toolbars are covered by the mainWidget
    3. 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
    4. 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,
    Attached Images Attached Images
    Last edited by qtUser500; 23rd February 2009 at 20:37.

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

    Default Re: Help needed in adding QWidget and other objects to a QHBoxLayout

    Quote Originally Posted by qtUser500 View Post
    I am using Qt 3.3.5
    Ouch Can you consider upgrading to Qt 4.4.3?

    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".

    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
    Attached Files Attached Files
    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.


  3. #3
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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.

  4. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help needed in adding QWidget and other objects to a QHBoxLayout

    Quote Originally Posted by qtUser500 View Post
    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.

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

    Default Re: Help needed in adding QWidget and other objects to a QHBoxLayout

    Quote Originally Posted by qtUser500 View Post
    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.

    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.

    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.

    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.

    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.

    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.
    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.


  6. The following user says thank you to wysota for this useful post:

    qtUser500 (24th February 2009)

  7. #6
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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.
    • 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:

    Qt Code:
    1. QBoxLayout* docLayout = new QHBoxLayout( docFrame );
    2. docLayout->add(documentView); // 'documentView' is the object I want in the layout and eventually in the QFrame
    To copy to clipboard, switch view to plain text mode 

    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 !
    Last edited by qtUser500; 24th February 2009 at 18:13.

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

    Default Re: Help needed in adding QWidget and other objects to a QHBoxLayout

    Use addWidget() and not add().
    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.


  9. #8
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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!
    Attached Images Attached Images

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

    Default 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.
    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.


  11. #10
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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.
    Qt Code:
    1. QHBoxLayout* docLayout = new QHBoxLayout(docFrame);
    To copy to clipboard, switch view to plain text mode 

    documentView:
    Qt Code:
    1. documentView= new ViewClass(QWidget*, QString); // Changed due to propriety reasons
    To copy to clipboard, switch view to plain text mode 

    Thanks for UR time wyosa, it is really appreciated!
    Attached Files Attached Files

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

    Default 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.
    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.


  13. #12
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default 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!

Similar Threads

  1. Replies: 1
    Last Post: 8th February 2009, 11:37
  2. QHBoxlayout Size problem
    By Spitz in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2008, 21:09
  3. Drawing on QWidget - strech & resize
    By kemp in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2007, 14:39
  4. QHBoxLayout Problem
    By Seema Rao in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2006, 15:51

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.