Results 1 to 5 of 5

Thread: Regarding alignment in QTable

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Unhappy Regarding alignment in QTable

    Hai guys,

    Qt Version : Qt 3.3.4
    Problem : Regarding alignment in QTable

    I am facing a porblem ., I need to align the cell_data in QTable to Left/ Right as per certain conditons.
    One of my friends get a reply from forum that " you can set the alignment, setting all alignment of the text contents of the tableItems.. ". But i didnot see any function in the Qt Assistant like this instead of " int QTableItem::alignment () const [virtual] "


    My need is something like this QTableItem::setAlignment( Alignment ) .

    Please help me if you can

    Thanks

  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: Regarding alignment in QTable

    You have to reimplement alignment() in a subclass of QTableItem and return proper alignment you wish the item to have, for example:

    Qt Code:
    1. int MyTableItem::alignment(){
    2. if(text()[0]=='X') return Qt::AlignLeft; // align left for items beginning with "X"
    3. return Qt::AlignRight; // align right for others
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    joseph (5th December 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Unhappy Re: Regarding alignment in QTable

    I have implemented like as below ... but not working the alignment to LEFT

    Qt Code:
    1. class MyTableItem : public QTableItem
    2. {
    3.  
    4. public:
    5. MyTableItem( QTable * table, EditType editType, const QString & text )
    6. :QTableItem ( table, editType, text )
    7. {
    8.  
    9. }
    10. ~MyTableItem()
    11. {
    12. /*NOOP*/
    13. }
    14. int alignment()
    15. {
    16. return Qt::AlignLeft; //or Qt::AlignRight;
    17.  
    18. }
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    Then inside my MyMainWindow Class.... as follows

    Qt Code:
    1. ------
    2. -----
    3. void MyMainWindow :: refreshTable()
    4. {
    5. ----
    6. myTable->setItem( row , col, new MyTableItem( myTable , QTableItem::Never, TextInCell );
    7. ---
    8. }
    To copy to clipboard, switch view to plain text mode 

    I have debugged the code , the control comes in alignment() of MyTableItem...

    please lead me to a right way if i am wrong..

    Thank you
    Last edited by wysota; 5th December 2006 at 10:57. Reason: missing [code] tags

  5. #4
    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: Regarding alignment in QTable

    It should be "int alignment() const" and not "int alignment()".

  6. #5
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Regarding alignment in QTable


    Thank you so much ..It's working fine
    I use this opertunity to thank you onbehalf of our team.

Similar Threads

  1. copy-paste the content of a QTable
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2006, 12:20
  2. QTable gives error when put on a dialog??
    By darpan in forum Qt Tools
    Replies: 3
    Last Post: 7th August 2006, 19:57
  3. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  4. Problem with QTable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:00
  5. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:03

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.