Q table widget problem, Urgent!!!!!!



  • QT table widget , Hello guys i have a doubt with regards to table widget. I am devleloping the GUI. I use the designer to dot the designing and the development is done in c++, so i have a header file and .cpp file named Control window, and i have created a 3 table widget using designer, and their respective items has been declered in the header files. in the constructor .cpp file i create the rows and columns and in my function setdata i update the datas with my incoming dynamic datas which keep changing. Now the problem is by default when i click the header of the tablewidget which are by the way column names given in the designer the data gets sorted, but i have few empty blanks which are coming up during the sort. once clicked ascending happens and next time descending. while ascending the empty rows are coming up. How can i solve the problem??

    Constraints:
    The dynamic datas are of integer type.
    I cannot use tableview.
    I have to imlement the same for % more tablewidget items.


  • Moderators

    @VInay123 Hi, and welcome to the Qt forum!

    How can i solve the problem?

    That's some bug in your code and you need to fix it. Sorry but how should anyone here be able to help you with this?



  • @Wieland Hi thank you for the reply. Actually i am using default sorting criteria enabled. I.e Set sortEnabled(true);

    I have a table of 20 rows constructed in the constructor. And i get some data which can be less than 20 but not more than that. I put that datas in the rows. as the data is being updated dynamically, sometime only two rows are filled and sometimes 10 and meanwhile when i click the header or column name it gets sorted. whilewhile ascending say i have only 10 rows filled and rest 10 are empty, when i click the column the empty 10 are coming first and later the filled onces according to ascending oreder.


  • Moderators

    @VInay123 Okay, understood. Try to disable sorting before you insert new elements and after that reenable it again. (void QTableView::setSortingEnabled(bool enable)).



  • So i should disable the sorting in my constructor, and in my function where i put the elements in the table after the loop i should enable it?



  • @Wieland I tried doing it, but still i have the same problem. :(


  • Moderators

    Maybe the workaround mentioned in QTBUG-7483 can help.


  • Qt Champions 2016

    @VInay123 said:

    i have created a 3 table widget using designer, and their respective items has been declered in the header files.

    What items are declared in the header, how and why? Please show how you populate the widget(s) and other relevant pieces of the code.

    I cannot use tableview.

    You are already using a table view. QTableWidget derives from QTableView.

    Also what version of Qt are you using?



  • @kshegunov
    From the designer i get a header file where the Qtablewidget is declared.

    I have a separate cpp and header file for development process, this header file has the inclusion of the header file obtained from designer.

    In the development header file i declare a pointer of Qtablewidget items[][];

    and in cpp the constructor i populate the items so a table is created .

    and in my funtion i fill the table

    I use qt 4.7.8


  • Moderators

    @VInay123 said:

    I use qt 4.7.8

    Ok, then it's clearly the bug I refered to before, QTBUG-7483.



  • @Wieland when we click the column names of the table widget i get a small arrow inside and sorting happens one click ascending and one click descending. How do i disable it?? i tried setsortingenabled(false) but its still sorting


  • Moderators

    @VInay123 I can only test it with Qt 5.6. With this, in the designer there is a property sortingEnabled. When this isn't selected I don't get the small arrow and clicking the header does not cause any sorting.


  • Moderators

    @VInay123 Also with Qt 5.6 ascending and descending sorting works as expected. Can't you update to a more recent Qt version?



  • @Wieland I havent check that box of sort enabled in the property box, but it is in bold compared to other properties. And because i work with a other software called ADTF , higher versions are not compatible :(



  • @Wieland
    I have a question, i think i could use the signal when i click header.

    Actually with designer i have created rows and column names. now i would like to use the signal when i click the column.
    right now i use QObject::connect(ui.tablewidget->verticalheader(), SIGNAL(sectionPressed(int)), this, SLOT(function(int))).
    But i am never receiving a signal. I tried using sectionClicked(int) or sectionDoubleClicked(int). which is an approporiate one to know whther a user has clicked the header or column name ones or twice?


  • Moderators

    @VInay123 Hi! This works for me (Qt 5.6):

    connect( ui->tableWidget->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sayHi()) );
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.