Results 1 to 5 of 5

Thread: Can a Qwidget belong to two different layouts

  1. #1
    Join Date
    Apr 2008
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can a Qwidget belong to two different layouts

    My problem is that I have created a QTextEdit and I want this widget to appear in two different dialogs, so if I change the value in the one layout the value to change in the other layout. Is such a configuration possible?

    A minimal example is more than welcome.

    Thanks in advance...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Can a Qwidget belong to two different layouts

    Hi,

    • create two QLineEdits's
    • connect them using the signal slot mechanism


    Qt Code:
    1. connect(edit1, SIGNAL(textChanged(const QString&)), edit2, SLOT(setText(const QString&)));
    2. connect(edit2, SIGNAL(textChanged(const QString&)), edit1, SLOT(setText(const QString&)));
    To copy to clipboard, switch view to plain text mode 

    EDIT: äh, QTextEdit... The same concept but use textChanged() signal and connect to a custom slot where you change the value of the other edit...

  3. #3
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can a Qwidget belong to two different layouts

    also it is possible to use one QTextEdit object and change the parent and geometry of the object when needed but that wouldn't be a good solution and it wouldn't be possible to show the two widgets at the same time.

    creating two QTextEdit objects makes much sense.

  4. #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: Can a Qwidget belong to two different layouts

    Quote Originally Posted by Lykurg View Post
    EDIT: äh, QTextEdit... The same concept but use textChanged() signal and connect to a custom slot where you change the value of the other edit...
    There is a nicer solution:

    Qt Code:
    1. QTextEdit *te1 = new QTextEdit;
    2. QTextEdit *te2 = new QTextEdit;
    3. te2->setDocument(te1->document());
    To copy to clipboard, switch view to plain text mode 
    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.


  5. The following 2 users say thank you to wysota for this useful post:

    alisami (22nd May 2009), Lykurg (22nd May 2009)

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Can a Qwidget belong to two different layouts

    Quote Originally Posted by wysota View Post
    There is a nicer solution
    Wow, of course, I haven't thought of that possibility. Qt is great...

Similar Threads

  1. QtScript Binding problem with QWidget
    By zack in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 09:38
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  5. tableview and layouts
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2007, 17:21

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.