Results 1 to 20 of 20

Thread: table in QLabel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    Quote Originally Posted by piotrpsz
    label->layout()->setSpacing( ... ),
    label->layout()->setMargin( ... ),
    But it makes "segmentation fault"...

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

    Default Re: table in QLabel

    QLabel is not a container, thus it doesn't have a layout (unless you provide one, but I don't know what will happen then... QLabel is not supposed to have a layout).

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: table in QLabel

    What can I do to avoid this red border above, below
    i did some testing on QT4. I know you're on QT3, but i wanted to see the behaviour here also.

    QT4 doesn't provide the left and right margins, but you get top and bottom margins. So this is better than QT3.

    But the margins on top and bottom arestill there.
    I noticed I could drag the dialogbox to a minimum size = sizehint of the textlabel. I couldn't drag it smaller. (because of QT's wonderfull sizehint functionality)

    So here is my dirty trick :
    label->resize(1,1);//resize it to 1 by 1 pixel, which QT won't allow.

    and in QT4 the dialogbox is the size you want without the margins.

    I hope it will work for QT3 also.

    Cheers

  4. #4
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    Quote Originally Posted by Everall
    So here is my dirty trick :
    label->resize(1,1);//resize it to 1 by 1 pixel, which QT won't allow.
    It resize this QLabel ALWAYS to minimal size, so the table is without margins, but Qt doesn't show the whole table...
    Qt Code:
    1. QLabel *label = new QLabel(0);
    2. label->resize(1,1);
    3. label->setFrameStyle(QFrame::Plain);
    4. label->setBackgroundMode(Qt::FixedColor);
    5. label->setPaletteBackgroundColor(QColor("red"));
    6. label->setText("<table width=\"100%\" bgcolor=white border=0 cellspacing=0 cellpadding=0><tr><td>aaa<br>ccc<br>ddd</td><td>bbb</td></tr></table>");
    7. label->show();
    To copy to clipboard, switch view to plain text mode 
    gives:

    How does it look on Qt4?

    I've seen in some sources this trick with resize(1,1), but I don't remember exacly where it was... I'll look for it.
    Last edited by Pan Wojtas; 6th February 2006 at 15:34.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: table in QLabel

    How does it look on Qt4?
    it looks like :

    Cheers
    Attached Images Attached Images

  6. #6
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by wysota
    QLabel is not a container, thus it doesn't have a layout (unless you provide one, but I don't know what will happen then... QLabel is not supposed to have a layout).
    QLabel is a QWidget.
    Every QWidget have a layout (QWidget have a function member QLayout* layout()).
    Maybe is not used, but have layout.

    Piotr

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

    Default Re: table in QLabel

    Quote Originally Posted by piotrpsz
    QLabel is a QWidget.
    Every QWidget have a layout (QWidget have a function member QLayout* layout()).
    Maybe is not used, but have layout.
    Eeem.... no.

    Qt Code:
    1. #include <qwidget.h>
    2. #include <qlayout.h>
    3. #include <qapplication.h>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QWidget *w = new QWidget();
    8. w->layout()->setMargin(5);
    9. delete w;
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    On my system it crashes on "w->layout()->setMargin()" call, meaning there is no layout in the widget. A class may have methods to get or set a layout, but it doesn't mean it uses them. If you take a look at QWidget sources, you'll notice, that it only references "layout" while dealing with "height for width".

  8. #8
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by wysota
    Eeem.... no.

    Qt Code:
    1. #include <qwidget.h>
    2. #include <qlayout.h>
    3. #include <qapplication.h>
    4.  
    5. int main(int argc, char **argv){
    6. QApplication app(argc, argv);
    7. QWidget *w = new QWidget();
    8. w->layout()->setMargin(5);
    9. delete w;
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

    On my system it crashes on "w->layout()->setMargin()" call, meaning there is no layout in the widget. A class may have methods to get or set a layout, but it doesn't mean it uses them. If you take a look at QWidget sources, you'll notice, that it only references "layout" while dealing with "height for width".
    OK
    Sorry, I should tell, that every widget CAN have a layout.
    Look a previous my post.

    Best regards
    Piotr

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

    Default Re: table in QLabel

    So set a layout for QWidget and try to do anything meaningfull with it...

  10. #10
    Join Date
    Jan 2006
    Location
    Poland/Poznań
    Posts
    14
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: table in QLabel

    I've noticed, that this extra margin on the bottom is always equal
    to "fontMetrics().height()", so it seems that Qt adds one empty line below
    each table...

  11. #11
    piotrpsz Guest

    Default Re: table in QLabel

    Quote Originally Posted by Pan Wojtas
    But it makes "segmentation fault"...
    That's right.
    For label function layout() returns 0 (NULL).

    But try this code:

    Qt Code:
    1. QLabel* lbl = new QLabel( "cos_niecos", this );
    2. QHBoxLayout* lbl_layout = new QHBoxLayout( lbl );
    3. QLayout* lay = lbl->layout();
    4.  
    5. if( 0 == lay ) qWarning( "lay is 0" );
    6. else qWarning( "OK" );
    7.  
    8. lbl->layout()->setMargin( 0 );
    9. lbl->layout()->setSpacing( 0 );
    To copy to clipboard, switch view to plain text mode 

    This code functioning.
    Piotr

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  3. Replies: 3
    Last Post: 5th October 2008, 23:41
  4. Replies: 3
    Last Post: 17th July 2008, 07:43
  5. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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
  •  
Qt is a trademark of The Qt Company.