Results 1 to 8 of 8

Thread: QTableView - alignment/selection problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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: QTableView - alignment/selection problem

    but it goes back to being right aligned once you finish editing - right?

    See if the following works better:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    3. {
    4. ui->setupUi(this);
    5.  
    6. ui->tw->setColumnCount(4);
    7. ui->tw->setRowCount(4);
    8.  
    9. for(int row=0; row < ui->tw->rowCount(); row++)
    10. {
    11. for(int col=0; col < ui->tw->columnCount(); col++)
    12. {
    13. QTableWidgetItem *twi = new QTableWidgetItem(QString("row%1 col%2").arg(row+1).arg(col+1));
    14. if(col == 2)
    15. twi->setTextAlignment(Qt::AlignRight);
    16. ui->tw->setItem(row,col,twi);
    17.  
    18. }
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    I'm attaching the project just in case.

    hope this helps. I'm also still learning.
    Attached Files Attached Files
    Last edited by schnitzel; 29th November 2009 at 05:19. Reason: updated contents

  2. #2
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - alignment/selection problem

    Quote Originally Posted by schnitzel View Post
    but it goes back to being right aligned once you finish editing - right?
    No. That is not right. Is should be right aligned all the time. That is why I have created my own delegate.

    I have no problem with alignment. The problem is that text selection in right aligned cell doesn't work. See my example.

  3. #3
    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: QTableView - alignment/selection problem

    sorry, but maybe I'm not getting it. See attached picture.
    In both cases, when I type text it is indeed left aligned, but once you hit enter, the new text is right aligned. Just curious why that is such a problem for you.
    Attached Images Attached Images

  4. #4
    Join Date
    May 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - alignment/selection problem

    Quote Originally Posted by schnitzel View Post
    sorry, but maybe I'm not getting it. See attached picture.
    In both cases, when I type text it is indeed left aligned, but once you hit enter, the new text is right aligned. Just curious why that is such a problem for you.
    Ok. One more time:
    I have no problem with alignment. The problem is that text selection in right aligned cell doesn't work. Please see my example. Copy it, paste to main.cpp, complie and run. You will see that there is no problem with alignment.

    Notice also that I have used AllEditTriggers so there is no need to double click on the cell.

    Run my program move cursor to the first cell in the middle column (which is right aligned), place mouse cursor bewteen letters "o" and "w" and then click. This selects whole word and text cursor is at the end of the word.

    This should select only "ro" part of the word and the text cursor should be between "o" and "w" (text cursor should be under mouse cursor).

    Now do the same in left aligned column and you will see the difference.

  5. #5
    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: QTableView - alignment/selection problem

    Yes, I can even reproduce it in my example once I select the 'AllEditKeys'.

    Is there a particular reason why you want to set it to AllEditKeys?

    By default it is set to DoubleClicked|EditKeyPressed|AnyKeyPressed, which I find works reasonable.

    Have you tried a different input widget instead of line edit? Maybe those are better for customizing the behavior you want.

    sorry I can't be of more help.

Similar Threads

  1. QTreeView problem scrolling to end.
    By seneca in forum Qt Programming
    Replies: 7
    Last Post: 22nd December 2015, 12:08
  2. Problem with KeyPress event and QTableView
    By ranna in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:01
  3. Replies: 1
    Last Post: 23rd December 2008, 15:42
  4. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Tags for this Thread

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.