Results 1 to 10 of 10

Thread: PRIMARY Selections

  1. #1
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default PRIMARY Selections

    Linux has three Selection mechanism for copy and past operations: PRIMARY, SECONDARY, CLIPBOARD.

    How can i get both CLIPBOARD and PRIMARY selections to set a QLineEdit's text.

    when a text is selected in any window then PRIMARY Selection occurs. And the text is implicitly exists in PRIMARY Selection buffer. When user clicks middle mouse button text is pasted to focused window. I need the text as soon as it appears/changes in PRIMARY Selection buffer.

    For example double clicking a text highligths the text, how can i get this text automatically into a qwidget(after double clicking). I wrote similar operation via QClipboard but it needs to explicit copy (menu->copy or Ctrl+C) on most of editors and text shown windows.
    If i use QClipboard it runs perfectly (because it automatically copies the selection to QClipboard i think) on QT Assistant's text but Open office word processor or Mozilla selections needs Ctrl+C.
    Last edited by hayati; 11th September 2006 at 10:14. Reason: extra description

  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: PRIMARY Selections

    Qt Code:
    1. QClipboard *clip = QApplication::clipboard();
    2. clip->setText(lineEdit->text(), QClipboard::Clipboard); // copy to global clipboard
    3. clip->setText(lineEdit->text(), QClipboard::Selection); // copy to selection clipboard
    To copy to clipboard, switch view to plain text mode 
    Is that what you want?

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

    hayati (11th September 2006), sunil.thaha (12th September 2006)

  4. #3
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: PRIMARY Selections

    yes it has similar functionality. but operation is reverse. i.e. selection buffer to lineEdit. Getting selection buffer at any time is not the issue.

    Qt Code:
    1. //constructor
    2. m_pClipBoard = QApplication::clipboard();
    3. connect(m_pClipBoard, SIGNAL(selectionChanged()), this, SLOT(someFunc()));
    4.  
    5. //some Func
    6. QString m_sKeyword = m_pClipBoard->text(QClipboard::Selection)
    To copy to clipboard, switch view to plain text mode 

    the problem is Selection buffer changes asynchroniously and from another application's window (ex:Mozilla, Open Office Writer etc.). And QT documentation says that:

    X11 also has the concept of ownership; if you change the selection within a window, X11 will only notify the owner and the previous owner of the change, i.e. it will not notify all applications that the selection or clipboard data changed.
    Lastly, the X11 clipboard is event driven, i.e. the clipboard will not function properly if the event loop is not running. Similarly, it is recommended that the contents of the clipboard are stored or retrieved in direct response to user-input events, e.g. mouse button or key presses and releases. You should not store or retrieve the clipboard contents in response to timer or non-user-input events.
    so signals (selectionChanged() and dataChanged)) are not sent to my application. then i can't get any selectionChange() signal. But if i check the Selection buffer in a endless while loop i see the changes but it wastes much cpu. this behaviour is also against qt's advise.

    Any solution/suggestion to do this without using a timer, endless loops.
    Last edited by hayati; 11th September 2006 at 15:38. 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: PRIMARY Selections

    Use a timer. That's the only way - a timer with one, two second timeout. You won't need a better resolution anyway. I just have a question -- what do you need it for?
    Last edited by wysota; 11th September 2006 at 17:01.

  6. #5
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: PRIMARY Selections

    i'm writing a dictionary just behaves like babylon. (Actually it has finished with this functionality) As babylon translates the highlighted-text to target language i need the highlighted text somehow. Unfortunately Acrobat files does not seem to be used as easy.

    i noticed something, the text editor Kate is working perfectly even if i don't add any code (like timer). i think Kate forwards the signal to all windows perharps. the same behaviour can be seen on QT Assistant's help text. Weird!!??

    yes you're right. timer is the most efficient solution.

    Thanks
    Regards

  7. #6
    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: PRIMARY Selections

    It's not Kate or Assistant. It is X11's responsibility to map selections to clipboard selections. It should work with all Qt widgets out of the box too. Maybe it is Acrobat which causes the trouble? Maybe it uses some kind of artificial selection?

  8. #7
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: PRIMARY Selections

    right i've just tested it with other qt applications then it worked. But unfortunately mozilla, open office, and most of the other programs are not qt based (i think so). because they don't work while qt based applications work. i haven't tested it with acrobat, but even babylon does not work acrobat reader in windows

    but i'm sure it doesn't work with non-qt widgets/applications.

  9. #8
    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: PRIMARY Selections

    Quote Originally Posted by hayati
    but i'm sure it doesn't work with non-qt widgets/applications.
    Hmm... it works fine for me... I tested kate->OO, OO->Firefox, Firefox->kate and OO->kate, all worked well.

  10. #9
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: PRIMARY Selections

    yes they speak each other with no problem. OO-->kate, mozilla-->OO middle click past operations are managed by X11. even my qt widget responses paste from selection buffer with middle mouse button click. this is ok.
    But non qt applications don't emit selectionChanged() signal except to owner and previous owner of selection-buffer/clipboard.
    So my application pastes the selection if you click to the lineEdit with middle mouse button as usual. But i want not to click middle mouse button on my lineEdit. As soon as change in selection buffer occurs than my lineEdit should get the selection in the buffer.
    it should act like babylon, in other words; my qt app's lineEdit widget should get selection buffer changes regardless from any other application - qt or nonqt. It should not need to get the selection buffer via middle button click.

    the point is qt applications( kate, qt assistant) emits selectionChanged() to my application even if my application isn't the owner and previous owner. But mozilla, OO and most of the other programs don't emit this signal. they emit this signal only to owner and prev owner. this statement is standard of X11 as stated qt docs.

  11. #10
    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: PRIMARY Selections

    Quote Originally Posted by hayati
    So my application pastes the selection if you click to the lineEdit with middle mouse button as usual. But i want not to click middle mouse button on my lineEdit. As soon as change in selection buffer occurs than my lineEdit should get the selection in the buffer.
    it should act like babylon, in other words; my qt app's lineEdit widget should get selection buffer changes regardless from any other application - qt or nonqt. It should not need to get the selection buffer via middle button click.
    Strange requirement, but ok. Use a timer as already suggested. In the timeout slot simply check if the content of the selection changed since last check and act accordingly.

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 18:31

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.