Results 1 to 4 of 4

Thread: acsessing QTextEdit from QTabWidget

  1. #1
    Join Date
    Sep 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default acsessing QTextEdit from QTabWidget

    so i'm making a small editor for FASM with Qt, i am building over the Syntax Highlighter Example that the Qt SDK comes with. i have syntax highlighting down and file I/O is going really well but i want to have tabs to mange multiple files at the same time. at first i thought "ok that's easy i just make QTabWidget my central widget and add QTextEdit child's to it." the issue with this is that i cant find a way to access the actual QTextEdit becuase i can only access the QWidget of the tab. im not sure how QTextEdit works witch makes finding a solution some what difficult. if there is a way to alter the actual Widget indexed by each tab as a QTextEdit and maintain all needed information to display them correctly.

    here is some code showing my problem, how do i alter the properties of the current widget as a QTextEdit.

    Qt Code:
    1. void MainWindow::openFile(const QString &path)
    2. {
    3. QString fileName = path;
    4. QTextEdit Tabed_Editor(Tabs->currentWidget());
    5. if (fileName.isNull())
    6. fileName = QFileDialog::getOpenFileName(this,
    7. tr("Open File"), "", "ASM Files (*.asm *.inc);; All(*.*)");
    8.  
    9. if (!fileName.isEmpty()) {
    10. QFile file(fileName);
    11. if (file.open(QFile::ReadOnly | QFile::Text))
    12. Tabed_Editor.setPlainText(file.readAll()); ///here this will not actully edit the current widit as it is a copy but how else would i edit it?
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: acsessing QTextEdit from QTabWidget

    Qt Code:
    1. QTextEdit *editor = qobject_cast<QTextEdit *>(Tabs->currentWidget());
    2.  
    3. ...
    4.  
    5. editor->setPlainText(...);
    To copy to clipboard, switch view to plain text mode 

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

    ishkabible (14th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: acsessing QTextEdit from QTabWidget

    thanks, i thought this would use a template but i had not seen any documentation that would allow for this kind of conversion (i was only looking within the classes them self's), thanks again

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: acsessing QTextEdit from QTabWidget

    Just a note:
    Always check if the object exists after casting and before using it. Otherwise you'll get a crash.

Similar Threads

  1. QTabWidget
    By Freeman551 in forum Qt Programming
    Replies: 3
    Last Post: 25th December 2009, 00:06
  2. QTabWidget
    By conatic in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2008, 20:05
  3. QTabWidget
    By allstar in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2007, 19:18
  4. QTabWidget tab
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2007, 00:16
  5. Replies: 1
    Last Post: 16th February 2007, 07:22

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.