Results 1 to 3 of 3

Thread: QWidget containing two QToolButtons

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QWidget containing two QToolButtons

    Hi! I want to set a QWidget that is composed of two QToolButtons as the cornerWidget of a QTabWidget, but it doesnt work. The buttons are being squeezed and aren't usable any more. Outside of the QTabWidget the widget looks ok.

    Any Ideas?
    Thanx

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. // #include "main.moc"
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. QWidget *w = new QWidget;
    10. QToolButton * butA = new QToolButton;
    11. QToolButton * butB = new QToolButton;
    12. // layout
    13. QHBoxLayout * lo = new QHBoxLayout(w);
    14. lo->addWidget(butA);
    15. lo->addWidget(butB);
    16.  
    17. QTabWidget * tabWidget = new QTabWidget;
    18. tabWidget->addTab(new QWidget(), "test tab");
    19. tabWidget->setCornerWidget(w, Qt::TopRightCorner);
    20. tabWidget->show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 1st October 2007 at 22:35. Reason: reformatted to look better

  2. #2
    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: QWidget containing two QToolButtons

    I think you'll need to alter the width and height of scrollbars to be able to put a larger than expected widget there. And that involves changing the application style or enforcing static sizes through manual setMinimumSize() calls.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QWidget containing two QToolButtons

    Someone in the qt irc room pointed me towards another solution. setting the Layouts contents margin to 0.
    QLayout::setContentsMargins(0,0,0,0); does the job. he docs say: "Only the horizontal element of the corner will be used.".

    That's what I was told in the irc channel:
    the corner widget respects the horizontal sizehint, but not the vertical, so it was allocating extra horizontal height for the margins, but not vertically... instead it squashed it.
    Applied the proposed change and it works.

    Thanks
    Last edited by momesana; 2nd October 2007 at 00:34.

Similar Threads

  1. Reuse a Qwidget with a QStackWidget
    By ucomesdag in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2007, 02:47
  2. Replies: 4
    Last Post: 24th April 2007, 13:18
  3. Replies: 3
    Last Post: 8th March 2007, 14:54
  4. QTextEdit, sizeHint, QWidget
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 08:25
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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.