Results 1 to 10 of 10

Thread: QTableView Splitter and pictures

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView Splitter and pictures

    Hello,

    I'm fresh to qt and to linus, I like it.

    What I would like is a form, it already has a mainmenu, that contain two things, a QTableView (showing a mysql database, that part is already working) and some container for some jpeg's, and these two divided by a splitter. Something like:

    [tableview]
    [--splitter--]
    [jpg jpg jpg]

    I would like to know how to do this with the designer to get more aquainted with it but I also wouldn't mind other help, ie code. Because I'm new it's still kind of overwhelming trying to get some work done.

    Thanks, Jean.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    You can't add a splitter in designer.
    It is better to do it in code - there's no way better to learn.
    For an example:
    Qt Code:
    1. QSplitter* splitter = new QSplitter(Qt::Vertical, someParentWidget);
    2. QTableView *table = new QTableView;
    3. ...
    4. splitter->addWidget(table);
    5.  
    6. QLabel *label = new QLabel; //for displaying the jpeg
    7. ...
    8. splitter->addWidget(label);
    9.  
    10. //next, add the splitter to some container widget.
    To copy to clipboard, switch view to plain text mode 

    You can find a lot more examples in the Qt Demos. Just browse around...

  3. #3
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    Thanks Marcel

    I followed your advice but have not much luck yet, I'm brand new you know.

    You said : //next, add the splitter to some container widget.

    Can you give an example?
    I thought that splitter already has a parent in it's constructor.
    The form now comes up with the view and the label only a few pixels in size.

    This is my code so far

    Qt Code:
    1. model->setTable("pix");
    2. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    3. model->select();
    4. QTableView *table = new QTableView;
    5. table->setModel(model);
    6. table->show();
    7. QLabel *label = new QLabel;
    8. QSplitter *split = new QSplitter(Qt::Vertical, centralwidget);
    9. split->addWidget(table);
    10. split->addWidget(label);
    To copy to clipboard, switch view to plain text mode 



    Thanks, Jean.
    Last edited by marcel; 29th December 2007 at 08:31. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    You said : //next, add the splitter to some container widget.
    I was meaning a layout, in case you have one. If the splitter is the central widget of your window then you do not need this step.

    The form now comes up with the view and the label only a few pixels in size.
    This is because your splitter has no layout manager to handle its size and position.
    Either set the splitter as the central widget of your main window or if you use a QDialog instead, then set a QHorizontalLayout as the dialog's layout and use layout->addWidget(splitter), causing it to resize to the full client area of the dialog.

    EDIT: if you want more control over the splitter's widget sizes the I suggest using QSplitter::setSizes() or QSplitter::setStretchFactor().
    Last edited by marcel; 29th December 2007 at 08:52.

  5. #5
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    Thanks Marcel,

    I'm looking at QSplitter::setSizes()
    I could maybe use screenheight returned from the desktop class to set heights..

    but..
    I was wandering how to do this:

    Quote Originally Posted by marcel View Post
    Either set the splitter as the central widget of your main window
    I hopefully tried
    split = centralwidget;

    But that is wrong

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    If you have a QMainWindow in your application then you should use, in one of the main window's members:
    Qt Code:
    1. setCentralWidget(splitter);
    To copy to clipboard, switch view to plain text mode 
    You should browse through the Qt examples. You can find a lot of useful stuff there, including splitters and main windows.

  7. #7
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    He Marcel,

    I gave up on the splitter for now, as this is my first linux/qt project I thought i'd better start with something more modest, also because I want to learn the designer.

    Thanks for the help,.

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    Quote Originally Posted by JeanC View Post
    I gave up on the splitter for now, as this is my first linux/qt project I thought i'd better start with something more modest, also because I want to learn the designer.
    Designer is just a tool. There is nothing you can do in Designer that you can't do in code.
    So my suggestion is to start browsing the examples and look at their sources. This is the only way you can learn.
    Playing with designer now will lead you nowhere.

  9. #9
    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: QTableView Splitter and pictures

    Quote Originally Posted by marcel View Post
    You can't add a splitter in designer.
    Sure you can. It's in the layouts section of icons.
    Attached Images Attached Images

  10. #10
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Splitter and pictures

    I understand and you are probably right in terms of learning proces. Still I like to play with designer a bit, call me pigheaded if you like, but I want to be able to use that tool for quick design.

    I have located the examples and I am still seeing things for the first time but I am learning and I will probably be on my way in a few days.

    Thanks.

    Quote Originally Posted by marcel View Post
    Designer is just a tool. There is nothing you can do in Designer that you can't do in code.
    So my suggestion is to start browsing the examples and look at their sources. This is the only way you can learn.
    Playing with designer now will lead you nowhere.

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.