我有一個X顯示器說:2。我想在給定的X 顯示屏上顯示我的qt小部件。該顯示與主顯示不同。因此,除了主顯示屏(由環境變量DISPLAY設置)之外,我還想訪問另一個X顯示屏。X顯示器的QDesktopWidget
我知道QDekstopWidget具有屏幕功能()。這不是我想要的。當我想使用 顯示ID直接訪問X顯示器時,I 有特殊情況。
讓我知道是否有反正這樣做。 更新:試過這種
#include<QApplication>
#include<QWidget>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Display* display = XOpenDisplay(":1");
XSynchronize(display, True);
//XSetErrorHandler(myErrorHandler);
Window x11root = XDefaultRootWindow(display);
int x = 0;
int y = 0;
unsigned int width = 500;
unsigned int height = 500;
unsigned int borderWidth = 0;
long colorBlue = 0xff0000ff;
Window x11w = XCreateSimpleWindow(display, x11root, x, y,
width, height, borderWidth, 1 /*magic number*/, colorBlue);
XMapWindow(display, x11w); // must be performed after XReparentWindow,
// otherwise the window is not visible.
QWidget w;
w.resize(200,200);
w.show();
XReparentWindow(display, w.winId(), x11w, 0, 0);
return a.exec();
}
試圖qscreen測試的建議。它的檢測顯示,但是這兩個窗口是怎麼回事顯示:3
[email protected]:/tmp/korvins-qtbase-6226fcdc3e4ace4636c58778ef53fbf69f46c36e-6226fcdc3e4ace4636c58778ef53fbf69f46c36e/tests/manual/qscreen$ ./qscreen -platform xcb::3::5
qt.core.logging: Loading "/home/shiva/.config/QtProject/qtlogging.ini" ...
qt.qpa.screen: Output VGA-1-0 is not connected
qt.qpa.screen: Output HDMI-1-0 is not connected
qt.qpa.screen: adding QXcbScreen(0x1b82f60, name="eDP-1-0", geometry=1366x768+0+0, availableGeometry=1309x744+57+24, devicePixelRatio=1.0, logicalDpi=QPair(96.0,96.0), physicalSize=344.0x194.0mm, screenNumber=0, virtualSize=1366x768 (1366.0x768.0mm), orientation=Qt::ScreenOrientation(LandscapeOrientation), depth=24, refreshRate=59.0, root=2c1, windowManagerName="Compiz") (Primary: true)
qt.qpa.screen: primary output is "eDP-1-0"
qt.qpa.screen: connecting to additional display: "" "3"
qt.qpa.screen: adding QXcbScreen(0x1bae540, name="TurboVNC", geometry=1024x716+0+0, availableGeometry=1024x664+0+28, devicePixelRatio=1.0, logicalDpi=QPair(96.0,96.0), physicalSize=271.0x189.0mm, screenNumber=0, virtualSize=1024x716 (1024.0x716.0mm), orientation=Qt::ScreenOrientation(LandscapeOrientation), depth=24, refreshRate=60.0, root=6a, windowManagerName="Metacity") (Primary: true)
qt.qpa.screen: primary output is "TurboVNC"
qt.qpa.screen: connecting to additional display: "" "5"
qt.qpa.screen: adding QXcbScreen(0x1bd6ca0, name="TurboVNC", geometry=1024x716+0+0, availableGeometry=1024x664+0+28, devicePixelRatio=1.0, logicalDpi=QPair(96.0,96.0), physicalSize=271.0x189.0mm, screenNumber=0, virtualSize=1024x716 (1024.0x716.0mm), orientation=Qt::ScreenOrientation(LandscapeOrientation), depth=24, refreshRate=60.0, root=6a, windowManagerName="Metacity") (Primary: true)
qt.qpa.screen: primary output is "TurboVNC"
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Could not initialize OpenGL for RasterGLSurface, reverting to RasterSurface.
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Could not initialize OpenGL for RasterGLSurface, reverting to RasterSurface.
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Xlib: extension "GLX" missing on display ":5".
Could not initialize OpenGL for RasterGLSurface, reverting to RasterSurface.
這是否改變什麼'XReparentWindow(顯示器,w.winId(),x11root,0,0);'(在我看來,你並不需要創建第二個窗口)?如果這沒有幫助,除了有兩個獨立的QApplications,我沒有更多的想法,但是你可能需要兩個進程。 – dmi
是的,你的權利創建第二個窗口應該沒有必要。它沒有與根窗口一起工作,所以我只創建了第二個窗口來嘗試。 –