Results 1 to 10 of 10

Thread: Header problem

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Header problem

    I have never tried this before, so in a new form I put into the constructor:
    Qt Code:
    1. model = new QStandardItemModel(this);
    2. ui->tvSpots->setModel(model); // QTableView
    3. header = new QHeaderView(Qt::Horizontal, this);
    4. ui->tvSpots->setHorizontalHeader(header);
    5. model->setHeaderData(0, Qt::Horizontal, "Click Connect to start");
    6. ui->tvSpots->show();
    To copy to clipboard, switch view to plain text mode 
    The table view shows up, but not the header.
    Any ideas?

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Header problem

    try adding:
    Qt Code:
    1. ui->tvSpots->horizontalHeader()->setVisible(true);
    To copy to clipboard, switch view to plain text mode 
    and try QString("Click Connect to start") for the third argument to setHeaderData().

    I'm using code similar to yours and that's the only difference I can see.
    Last edited by schnitzel; 22nd March 2011 at 03:29. Reason: spelling corrections

  3. The following user says thank you to schnitzel for this useful post:

    waynew (27th March 2011)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Header problem

    Thanks Schnitzel, but unfortunately, that didn't do it.

    I'm still working on it, but I added a debug and it says the setHeaderData returned false.
    No idea why yet.
    I have used this same type of code in a function in my mainwindow and it works perfectly.
    So for the moment, I am stumped.

  5. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Header problem

    can you attach a minimal project that contains the problem or show the entire code?

  6. #5
    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: Header problem

    Does the model contain any columns?
    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.


  7. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Header problem

    The model does not contain any columns at the time I attempt to set the header.
    However, I worked around the problem by using setHorizontalHeaderLabels and this is working ok.

    Thanks folks.

  8. #7
    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: Header problem

    Quote Originally Posted by waynew View Post
    The model does not contain any columns at the time I attempt to set the header.
    So no headers will be visible because there are no columns in the model. If you at least set a column count, the header might have something to display.
    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
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Header problem

    Quote Originally Posted by wysota View Post
    Does the model contain any columns?
    and wysota strikes again

    @waynew: Not sure why I deserved a thanks... you should give it to wysota.

  10. #9
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Header problem

    Well, maybe. But he is a very helpful person and he has taught me a lot. But at 67 years old, I know I will never catch up to him.

    Actually, I tried setColumnCount but that did not make any difference. The thing I do not understand is that I am doing this for another dialog from my main window and it works fine. The only differences I can see are that it is being done there from a function as opposed to the constructor here and there the model is a QSqlTableModel so of course it has db columns defined, so Wysota, you are probably correct about the columns. I just can't do it that way here since I need to dynamically change the header labels depending on what data is going to be received. So maybe the setHorizontalHeaderLabels is the best solution anyway.

  11. #10
    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: Header problem

    QStandardItemModel behaves differently than other models. If it doesn't have any rows, it ignores its column count and thus you get an empty viewport. You need to provide info about the columns manually just like you did (another way would be to use QStandardItemModel::setHorizontalHeaderItem()).
    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.


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

    waynew (29th March 2011)

Similar Threads

  1. problem in accessing qt header files
    By namus in forum Newbie
    Replies: 1
    Last Post: 4th June 2010, 11:35
  2. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  3. 'QFile' Header File Problem
    By hasnatzaidi in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 21:40
  4. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59
  5. Table header section click problem
    By Khal Drogo in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2008, 22:31

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.