Results 1 to 7 of 7

Thread: Adding widgets without using any layout. Is it possible?

  1. #1
    Join Date
    Aug 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Adding widgets without using any layout. Is it possible?

    Hi all,
    i'm new on Qt. I'm writing my own custom control extending the QWidget class. I need to put buttons on my control (like 1000 or 2000) and i would use the QPushbutton class.
    Is there a way to add buttons and labels to my custom control without putting them into any layout?

    Thanks in advance.

  2. #2
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    You can place those buttons and labels on a QFrame (as container). You will have to setGeometry() for each button and label. I think it should also work without using QFrame in which case you will have to pass some parent widget.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    I would advise against adding 1,000 - 2,000 QPushbutton's to a QWidget-derived object. Is there a reason why you need to use that many buttons?

  4. #4
    Join Date
    Aug 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    You will have to setGeometry() for each button and label. I think it should also work without using QFrame in which case you will have to pass some parent widget.
    I created my buttons and called setGeometry() for each one and It works. Many thanks.

    Is there a reason why you need to use that many buttons?
    I need to control the same number of objects. I'm implementing a grid with 1000-2000 rows and i would put a button on each one for hiding or showing.

    Maybe a better solution would be to draw the same amount of QImages and appropriately dispatch mouse events..

  5. #5
    Join Date
    Dec 2007
    Posts
    27
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    If you think about 2000 buttons keep the application performance in mind. All these objects have to be handled by the process with all their events and render schedules.
    Can I make a suggestion:
    Why don't you use a TableView with a button delegate. You can call "QAbstractItemView::setItemDelegate (...)" to set your own delegate. In the delegates paint method, you can simply paint a button with QStyleOptionButton and handle the events you need by yourself. What you got is a TableView filled with Buttons without having the overhead of the complex QPushButton instance. You will find example code in the Qt- Documentation.

  6. #6
    Join Date
    Aug 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    Like i said, i'm new on qt. Didn't know about the Qtableview.
    Each row of the grid can contain a non fixed number of other controls (other buttons, custom controls, ecc).
    Does the Qtableview allows to put Qwidgets on the table cells?

    You will find example code in the Qt- Documentation.
    Can you please post the link?

    Thanks

  7. #7
    Join Date
    Dec 2007
    Posts
    27
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding widgets without using any layout. Is it possible?

    The Star Delegate Example should be a good start. http://doc.qt.nokia.com/4.6/itemviews-stardelegate.html

    However, the QTableView has a defined column count. You cannot say that one row has a column count of 5 and the other a count of 3 for example. And it is quite complicate to show different controls for each field in the table (not imposible but tricky. Particularly if you want different controls in a row respectively in a column, because it is possible to set a delegate for a row / column but not for a field).

    Nevertheless I think you would not be lucky with 2000 constructed buttons / complex controls due to the performance issue.

Similar Threads

  1. Adding a Layout to QMainWindow
    By Chiggins in forum Qt Programming
    Replies: 2
    Last Post: 7th June 2010, 06:25
  2. Replies: 5
    Last Post: 18th April 2010, 23:31
  3. Replies: 5
    Last Post: 18th March 2010, 09:54
  4. A question about adding to layout
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 12:41
  5. Adding qpaint object to a Layout
    By Rooster in forum Newbie
    Replies: 6
    Last Post: 13th February 2008, 13:12

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.